Contacts and Commodities
This commit is contained in:
@@ -97,7 +97,6 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Portal.Controllers
|
||||
|
||||
// Item filter.
|
||||
SbmCommodity.Params prmCommodity = new SbmCommodity.Params();
|
||||
prmCommodity.AffiliateIdOrganisation = SessionData.Organisation.AffiliateId;
|
||||
prmCommodity.Search = model.Filter.CommoditySearch;
|
||||
prmCommodity.CommodityType = model.GetFilterCommodityType();
|
||||
prmCommodity.StatusCat = SbmCommodity.StatusCat.NotDeleted;
|
||||
@@ -134,7 +133,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Portal.Controllers
|
||||
TypeCode = Internals.CommodityTypeCodes.GetCodeForType(commodityType),
|
||||
TypeDesc = Internals.CommodityTypeCodes.GetDescForType(commodityType),
|
||||
Code = values.GetString(colCode.DataName),
|
||||
Desc= values.GetString(colDescBrief.DataName),
|
||||
Desc = values.GetString(colDescBrief.DataName),
|
||||
Notes = values.GetString(colNotes.DataName),
|
||||
StatusCode = values.GetString(colStatus.DataName),
|
||||
StatusDesc = SacsSystem.GetStatusDescForCode(values.GetString(colStatus.DataName)),
|
||||
@@ -150,8 +149,8 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Portal.Controllers
|
||||
// Refresh paging info.
|
||||
if (model.Paging.IsPaged)
|
||||
model.Paging.ItemCount = (ushort)responseData.Commodities.Count;
|
||||
SessionData.Commodities.Filter.PageNo = model.Paging.PageNo;
|
||||
SessionData.Commodities.Filter.PageLength = model.Paging.PageLength;
|
||||
SessionData_Portal.Profile.Commodities.Filter.PageNo = model.Paging.PageNo;
|
||||
SessionData_Portal.Profile.Commodities.Filter.PageLength = model.Paging.PageLength;
|
||||
responseData.SetPaging(model);
|
||||
|
||||
// Complete response.
|
||||
@@ -179,9 +178,10 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Portal.Controllers
|
||||
String messageTitle = Localiser["commodity.caption.commodity"];
|
||||
AjaxResponse_Commodity responseData = new AjaxResponse_Commodity(model);
|
||||
|
||||
// Validate session.
|
||||
if (!ValidUserSession)
|
||||
return GetAjaxResult_InvalidSession(responseData);
|
||||
// Validate session and referrer.
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
if (!ValidReferer) return Forbid();
|
||||
RefreshModel(model);
|
||||
|
||||
// Identify item.
|
||||
SysId commodityId = model.CommodityId.ToSysId();
|
||||
@@ -217,17 +217,31 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Portal.Controllers
|
||||
String messageTitle = Localiser["commodity.caption.commodity"];
|
||||
AjaxResponse_Commodity responseData = new AjaxResponse_Commodity(model);
|
||||
|
||||
// Validate session.
|
||||
if (!ValidUserSession)
|
||||
return GetAjaxResult_InvalidSession(responseData);
|
||||
// Validate session and referrer.
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
if (!ValidReferer) return Forbid();
|
||||
RefreshModel(model);
|
||||
|
||||
// Validate item properties.
|
||||
model.ValidateCommodityData(responseData);
|
||||
if (responseData.HasControlErrors())
|
||||
return Json(responseData);
|
||||
|
||||
// Retrieve existing item.
|
||||
// Validate item Id against 'Exists' flag.
|
||||
SysId commodityId = model.CommodityId.ToSysId();
|
||||
bool commodityExists = StringUtil.ToBool(model.CommodityExists);
|
||||
if (commodityExists && !SysId.IsValid(commodityId))
|
||||
{
|
||||
SaLogger.Warn(fn + " Id not specified for existing Commodity.");
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
if (!commodityExists && SysId.IsValid(commodityId))
|
||||
{
|
||||
SaLogger.Warn(fn + " Id specified for new Commodity: '" + model.CommodityId + "'");
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
|
||||
// Retrieve existing item.
|
||||
SbmCommodity commodity = CommodityMgr.GetCommodityById(commodityId);
|
||||
if (commodity == null && SysId.IsValid(commodityId))
|
||||
{
|
||||
@@ -244,13 +258,17 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Portal.Controllers
|
||||
}
|
||||
|
||||
// Populate item properties.
|
||||
if (model.CommodityType != null)
|
||||
commodity.CommodityType = model.GetCommodityType();
|
||||
if (model.CommodityCode != null)
|
||||
commodity.Code = model.CommodityCode;
|
||||
if (model.CommodityDesc != null)
|
||||
commodity.DescBrief = model.CommodityDesc;
|
||||
// Common properties.
|
||||
if (model.CommodityNotes != null)
|
||||
commodity.Notes = model.CommodityNotes;
|
||||
if (model.CommodityStatus != null)
|
||||
commodity.Status = model.GetCommodityStatus();
|
||||
if (model.CommodityStatusCode != null)
|
||||
commodity.Status = model.CommodityStatus;
|
||||
|
||||
// Store item.
|
||||
if (!SysId.IsValid(commodity.Id))
|
||||
@@ -260,6 +278,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Portal.Controllers
|
||||
SaLogger.Warn(fn + " Failed to insert commodity: " + CommodityMgr.ErrorStateMessage);
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.insert.failed"] + "\n\n" + CommodityMgr.ErrorStateMessage));
|
||||
}
|
||||
responseData.SetNotification(messageTitle, Localiser["msg.item.created"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -268,6 +287,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Portal.Controllers
|
||||
SaLogger.Warn(fn + " Failed to update commodity [Id:" + SysId.ToString(commodity.Id) + "]: " + CommodityMgr.ErrorStateMessage);
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.update.failed"] + "\n\n" + CommodityMgr.ErrorStateMessage));
|
||||
}
|
||||
responseData.SetNotification(messageTitle, Localiser["msg.item.updated"]);
|
||||
}
|
||||
|
||||
// Construct response.
|
||||
|
||||
@@ -42,8 +42,8 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Portal.Controllers
|
||||
|
||||
// Commodity page.
|
||||
Model_Commodity model = new Model_Commodity(Localiser);
|
||||
model.Paging.PageNo = SessionData.Commodities.Filter.PageNo;
|
||||
model.Paging.PageLength = SessionData.Commodities.Filter.PageLength;
|
||||
model.Paging.PageNo = SessionData_Portal.Profile.Commodities.Filter.PageNo;
|
||||
model.Paging.PageLength = SessionData_Portal.Profile.Commodities.Filter.PageLength;
|
||||
return View(model);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Portal.Controllers
|
||||
public String DisplayName { get; set; }
|
||||
public String TypeCode { get; set; }
|
||||
public String TypeDesc { get; set; }
|
||||
public bool? Individual { get; set; }
|
||||
// Address.
|
||||
public String AddressSummary { get; set; }
|
||||
}
|
||||
@@ -78,6 +79,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Portal.Controllers
|
||||
data.DisplayName = affiliate.GetDisplayName();
|
||||
data.TypeCode = Internals.AffiliateTypeCodes.GetCodeForType(affiliate.AffiliateType);
|
||||
data.TypeDesc = Internals.AffiliateTypeCodes.GetDescForType(affiliate.AffiliateType);
|
||||
data.Individual = affiliate.AffiliateType == Sbm.AffiliateType.Individual ? true : (bool?)null;
|
||||
// Common properties.
|
||||
data.Notes = affiliate.Notes;
|
||||
data.StatusCode = affiliate.StatusCode;
|
||||
@@ -153,8 +155,8 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Portal.Controllers
|
||||
|
||||
// Item filter.
|
||||
SbmAffiliate.Params prmAffiliate = new SbmAffiliate.Params();
|
||||
prmAffiliate.Search = model.Filter.AffiliateSearch;
|
||||
prmAffiliate.AffiliateType = model.GetFilterAffiliateType();
|
||||
prmAffiliate.Search = model.Filter.ContactSearch;
|
||||
prmAffiliate.AffiliateType = model.GetFilterContactType();
|
||||
prmAffiliate.StatusCat = SbmAffiliate.StatusCat.NotDeleted;
|
||||
prmAffiliate.SortColumns.Add(AccountMgr.GetAffiliateColumnDfn(SbmAffiliate.Column.Name));
|
||||
prmAffiliate.SortColumns.Add(AccountMgr.GetAffiliateColumnDfn(SbmAffiliate.Column.LastName));
|
||||
@@ -193,6 +195,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Portal.Controllers
|
||||
DisplayName = values.GetString(colName.DataName),
|
||||
TypeCode = Internals.AffiliateTypeCodes.GetCodeForType(affiliateType),
|
||||
TypeDesc = Internals.AffiliateTypeCodes.GetDescForType(affiliateType),
|
||||
Individual = affiliateType == Sbm.AffiliateType.Individual ? true : (bool?)null,
|
||||
AddressSummary = AccountMgr.GetAffiliateDataValue(colAddress, values).AsString(),
|
||||
Notes = values.GetString(colNotes.DataName),
|
||||
StatusCode = values.GetString(colStatus.DataName),
|
||||
@@ -209,8 +212,8 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Portal.Controllers
|
||||
// Refresh paging info.
|
||||
if (model.Paging.IsPaged)
|
||||
model.Paging.ItemCount = (ushort)responseData.Affiliates.Count;
|
||||
SessionData.Contacts.Filter.PageNo = model.Paging.PageNo;
|
||||
SessionData.Contacts.Filter.PageLength = model.Paging.PageLength;
|
||||
SessionData_Portal.Profile.Contacts.Filter.PageNo = model.Paging.PageNo;
|
||||
SessionData_Portal.Profile.Contacts.Filter.PageLength = model.Paging.PageLength;
|
||||
responseData.SetPaging(model);
|
||||
|
||||
// Complete response.
|
||||
@@ -235,12 +238,13 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Portal.Controllers
|
||||
public IActionResult Ajax_GetItem(Model_Contact model)
|
||||
{
|
||||
String fn = GetType().Name + ".Ajax_GetItem";
|
||||
String messageTitle = Localiser["affiliate.caption.affiliate"];
|
||||
String messageTitle = Localiser["contact.caption.contact"];
|
||||
AjaxResponse_Affiliate responseData = new AjaxResponse_Affiliate(model);
|
||||
|
||||
// Validate session.
|
||||
if (!ValidUserSession)
|
||||
return GetAjaxResult_InvalidSession(responseData);
|
||||
// Validate session and referrer.
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
if (!ValidReferer) return Forbid();
|
||||
RefreshModel(model);
|
||||
|
||||
// Identify item.
|
||||
SysId affiliateId = model.AffiliateId.ToSysId();
|
||||
@@ -273,20 +277,34 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Portal.Controllers
|
||||
public IActionResult Ajax_StoreItem(Model_Contact model)
|
||||
{
|
||||
String fn = GetType().Name + ".Ajax_StoreItem";
|
||||
String messageTitle = Localiser["affiliate.caption.affiliate"];
|
||||
String messageTitle = Localiser["contact.caption.contact"];
|
||||
AjaxResponse_Affiliate responseData = new AjaxResponse_Affiliate(model);
|
||||
|
||||
// Validate session.
|
||||
if (!ValidUserSession)
|
||||
return GetAjaxResult_InvalidSession(responseData);
|
||||
// Validate session and referrer.
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
if (!ValidReferer) return Forbid();
|
||||
RefreshModel(model);
|
||||
|
||||
// Validate item properties.
|
||||
model.ValidateAffiliateData(responseData);
|
||||
if (responseData.HasControlErrors())
|
||||
return Json(responseData);
|
||||
|
||||
// Retrieve existing item.
|
||||
// Validate item Id against 'Exists' flag.
|
||||
SysId affiliateId = model.AffiliateId.ToSysId();
|
||||
bool contactExists = StringUtil.ToBool(model.ContactExists);
|
||||
if (contactExists && !SysId.IsValid(affiliateId))
|
||||
{
|
||||
SaLogger.Warn(fn + " Id not specified for existing Affiliate.");
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
if (!contactExists && SysId.IsValid(affiliateId))
|
||||
{
|
||||
SaLogger.Warn(fn + " Id specified for new Affiliate: '" + model.AffiliateId + "'");
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
|
||||
// Retrieve existing item.
|
||||
SbmAffiliate affiliate = AccountMgr.GetAffiliateById(affiliateId);
|
||||
if (affiliate == null && SysId.IsValid(affiliateId))
|
||||
{
|
||||
@@ -296,16 +314,33 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Portal.Controllers
|
||||
|
||||
// Create new item if required.
|
||||
if (affiliate == null)
|
||||
affiliate = AccountMgr.CreateAffiliate(model.GetAffiliateType());
|
||||
{
|
||||
affiliate = AccountMgr.CreateAffiliate(model.GetContactType());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (model.ContactType != null)
|
||||
affiliate.AffiliateType = model.GetContactType();
|
||||
}
|
||||
|
||||
// Populate item properties.
|
||||
if (model.AffiliateName != null)
|
||||
affiliate.Name = model.AffiliateName;
|
||||
if (affiliate.IsIndividual())
|
||||
{
|
||||
if (model.ContactFirstName != null)
|
||||
affiliate.FirstName = model.ContactFirstName;
|
||||
if (model.ContactLastName != null)
|
||||
affiliate.LastName = model.ContactLastName;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (model.ContactName != null)
|
||||
affiliate.Name = model.ContactName;
|
||||
}
|
||||
// Common properties.
|
||||
if (model.AffiliateNotes != null)
|
||||
affiliate.Notes = model.AffiliateNotes;
|
||||
if (model.AffiliateStatus != null)
|
||||
affiliate.Status = model.GetAffiliateStatus();
|
||||
if (model.ContactNotes != null)
|
||||
affiliate.Notes = model.ContactNotes;
|
||||
if (model.ContactStatusCode != null)
|
||||
affiliate.Status = model.ContactStatus;
|
||||
|
||||
// Store item.
|
||||
if (!SysId.IsValid(affiliate.Id))
|
||||
@@ -315,6 +350,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Portal.Controllers
|
||||
SaLogger.Warn(fn + " Failed to insert affiliate: " + AccountMgr.ErrorStateMessage);
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.insert.failed"] + "\n\n" + AccountMgr.ErrorStateMessage));
|
||||
}
|
||||
responseData.SetNotification(messageTitle, Localiser["msg.item.created"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -323,6 +359,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Portal.Controllers
|
||||
SaLogger.Warn(fn + " Failed to update affiliate [Id:" + SysId.ToString(affiliate.Id) + "]: " + AccountMgr.ErrorStateMessage);
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.update.failed"] + "\n\n" + AccountMgr.ErrorStateMessage));
|
||||
}
|
||||
responseData.SetNotification(messageTitle, Localiser["msg.item.updated"]);
|
||||
}
|
||||
|
||||
// Construct response.
|
||||
|
||||
@@ -42,8 +42,8 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Portal.Controllers
|
||||
|
||||
// Contact page.
|
||||
Model_Contact model = new Model_Contact(Localiser);
|
||||
model.Paging.PageNo = SessionData.Contacts.Filter.PageNo;
|
||||
model.Paging.PageLength = SessionData.Contacts.Filter.PageLength;
|
||||
model.Paging.PageNo = SessionData_Portal.Profile.Contacts.Filter.PageNo;
|
||||
model.Paging.PageLength = SessionData_Portal.Profile.Contacts.Filter.PageLength;
|
||||
return View(model);
|
||||
}
|
||||
|
||||
|
||||
@@ -272,7 +272,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Portal.Controllers
|
||||
public static String Base64Key_OnlineApp { get; } = SacsEncryptionHelper.EncodePlainKey("{SaBusMgr=Portal-App#Encryption}", SacsEncryptionHelper.KeyLength);
|
||||
protected String EncryptOnlineParams(NameValueCollection parameters)
|
||||
{
|
||||
return HttpUtility.UrlEncode(EncryptParameters(parameters, SessionData_Portal.Base64IV_OnlineApp, Base64Key_OnlineApp));
|
||||
return HttpUtility.UrlEncode(EncryptParameters(parameters, SessionData_Portal.Base64IV_PortalApp, Base64Key_OnlineApp));
|
||||
}
|
||||
public static String EncryptOnlineParams(SbmController_Portal controller, NameValueCollection parameters)
|
||||
{
|
||||
@@ -280,7 +280,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Portal.Controllers
|
||||
}
|
||||
protected NameValueCollection ExtractOnlineParams(String encryptedParams)
|
||||
{
|
||||
return DecryptParameters(encryptedParams, SessionData_Portal.Base64IV_OnlineApp, Base64Key_OnlineApp);
|
||||
return DecryptParameters(encryptedParams, SessionData_Portal.Base64IV_PortalApp, Base64Key_OnlineApp);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user