Files
BeWoPlaner/BeWoPlanerMobil/Controllers/CustomerController.cs
Lyndon d1cd9401d7 .
2019-07-25 14:58:13 +02:00

84 lines
2.7 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using BeWoPlanerMobil.Models;
using BeWoPlanerMobil.Service;
using BS.Shared;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
using static BeWoPlanerMobil.Util.MobileUtils;
namespace BeWoPlanerMobil.Controllers
{
public class CustomerController : AbstractBaseController
{
private const string CustomerModelModelSessionKey = "CustomerModelModel";
private CustomerModel _Model;
public CustomerModel Model
{
get
{
if (!MobileSessionFacade.IsUserLoggedIn())
{
RedirectToActionPermanent("Index", "Login");
return null;
}
if (((CustomerModel) Session[CustomerModelModelSessionKey])?.Employee == null)
{
_Model = new CustomerModel {Employee = MobileSessionFacade.LoggedInEmployee};
Session[CustomerModelModelSessionKey] = _Model;
}
else
{
_Model = (CustomerModel)Session[CustomerModelModelSessionKey];
}
return _Model;
}
}
[Authorize]
public ActionResult Customer()
{
if (!MobileSessionFacade.IsUserLoggedIn() || Request.Browser.Browser.Equals("InternetExplorer"))
{
return RedirectToActionPermanent("Index", "Login");
}
var myRelatedCustomers = Model.Employee == null ? new List<CustomerEmployeeRelationDC>() : Model.Employee.RelatedCustomers;
if (MobileSessionFacade.CheckForUserRight(UserRightType.CustomerView_View))
{
Model.Customers = CustomerService.GetAllActiveCompactCustomers().OrderBy(k => k.LastName).ToList();
}
else if (MobileSessionFacade.CheckForUserRight(UserRightType.Customer_ViewMyCustomers))
{
Model.Customers = CustomerService.GetCompactCustomersById(myRelatedCustomers.Select(c => c.Customer.CustomerOid).ToList()).OrderBy(k => k.LastName).ToList();
}
else
{
Model.Customers = new List<CompactCustomerDC>();
}
return View(Model);
}
public string GetSelectedCustomer(long customerOid)
{
if (Model == null)
{
return "SessionTimeout";
}
Model.SelectedCustomer = CustomerService.LoadCustomer(customerOid);
Model.SelectedCustomerOid = customerOid;
return SerializeObject(GetJSONCustomer(Model.SelectedCustomer));
}
}
}