Web app logon.
This commit is contained in:
@@ -0,0 +1,400 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.App;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.Helpers;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.Portal.Models;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Consoles;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Helpers;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Mgr;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using Sarand.Net.Standard.Base.Email;
|
||||
using Sarand.Net.Standard.Base.Helpers;
|
||||
using Sarand.Net.Standard.Base.Security;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Core.Web.Portal.Controllers
|
||||
{
|
||||
//=======================================================================
|
||||
// Portal Association Controller - Ajax actions.
|
||||
//=======================================================================
|
||||
partial class AssociationController
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Association data.
|
||||
private class AssociationData_List : AjaxResponse_Data.ItemData_Base
|
||||
{
|
||||
public String OwnerId { get; set; }
|
||||
public String OwnerName { get; set; }
|
||||
public String TargetId { get; set; }
|
||||
public String TargetName { get; set; }
|
||||
public String TypeCode { get; set; }
|
||||
public String TypeDesc { get; set; }
|
||||
public String Code { get; set; }
|
||||
public String ReferenceExt { get; set; }
|
||||
public String Group { get; set; }
|
||||
public String DescDetail { get; set; }
|
||||
// Address.
|
||||
public String AddressSummary { get; set; }
|
||||
}
|
||||
private class AssociationData_Full : AssociationData_List
|
||||
{
|
||||
// Association properties.
|
||||
public String Location { get; set; }
|
||||
public String Role { get; set; }
|
||||
public String PhoneMain { get; set; }
|
||||
public String Email { get; set; }
|
||||
public String NominalCodeDefault { get; set; }
|
||||
}
|
||||
private void PopulateAssociationResponseData(SbmAssociation association, AssociationData_List data)
|
||||
{
|
||||
data.Id = SysId.ToString(association.Id);
|
||||
data.TypeCode = Internals.AssociationTypeCodes.GetCodeForType(association.AssociationType);
|
||||
data.TypeDesc = Internals.AssociationTypeCodes.GetDescForType(association.AssociationType);
|
||||
data.Code = association.Code;
|
||||
data.ReferenceExt = association.RefExt;
|
||||
data.Group = association.Group;
|
||||
data.DescDetail = association.DescDetail;
|
||||
// Common properties.
|
||||
data.Notes = association.Notes;
|
||||
data.StatusCode = association.StatusCode;
|
||||
data.StatusDesc = association.StatusDesc;
|
||||
}
|
||||
private void PopulateAssociationResponseData(SbmAssociation association, AssociationData_Full data)
|
||||
{
|
||||
PopulateAssociationResponseData(association, data as AssociationData_List);
|
||||
// Association properties.
|
||||
data.Location = association.Location;
|
||||
data.Role = association.Role;
|
||||
data.PhoneMain = association.PhoneMain;
|
||||
data.Email = association.Email;
|
||||
data.NominalCodeDefault = association.DefaultNominalCode;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Association list.
|
||||
//-------------------------------------------------------------------
|
||||
private class AjaxResponse_AssociationList : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_AssociationList(SbmModel_Portal model) : base(model) { }
|
||||
// Association list.
|
||||
public List<AssociationData_List> Associations { get; } = new List<AssociationData_List>();
|
||||
// Reference data.
|
||||
public List<CodeDesc> Statuses { get; } = new List<CodeDesc>();
|
||||
public String DefaultStatusCode { get; set; }
|
||||
}
|
||||
// Ajax request.
|
||||
[HttpPost]
|
||||
[Route("Association/Ajax/List")]
|
||||
[Route("Association/Ajax/GetList")]
|
||||
public IActionResult Ajax_AssociationList(Model_Association model)
|
||||
{
|
||||
String fn = GetType().Name + ".Ajax_AssociationList";
|
||||
AjaxResponse_AssociationList responseData = new AjaxResponse_AssociationList(model);
|
||||
String messageTitle = Localiser["association.caption.associations"];
|
||||
|
||||
// Validate session and referrer.
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
if (!ValidReferer) return Forbid();
|
||||
RefreshModel(model);
|
||||
|
||||
// Reference data - statuses.
|
||||
foreach (SaStatus status in SbmAssociation.ValidStatuses.FindAll(item => item != SaStatus.Deleted))
|
||||
responseData.Statuses.Add(SacsSystem.GetStatusCode(status), Localiser.GetStatusCaption(status));
|
||||
responseData.DefaultStatusCode = SacsSystem.GetStatusCode(SbmAssociation.DefaultStatus);
|
||||
|
||||
// Item filter.
|
||||
SbmAssociation.Params prmAssociation = new SbmAssociation.Params();
|
||||
prmAssociation.AffiliateIdOwner = SessionData.Organisation.AffiliateId;
|
||||
prmAssociation.Search = model.Filter.AssociationSearch;
|
||||
prmAssociation.AssociationType = model.GetFilterAssociationType();
|
||||
prmAssociation.StatusCat = SbmAssociation.StatusCat.NotDeleted;
|
||||
prmAssociation.SortColumns.Add(AccountMgr.GetAssociationColumnDfn(SbmAssociation.Column.Target_Name));
|
||||
model.Paging.ItemTotal = (ulong)AccountMgr.GetAssociationCount(prmAssociation);
|
||||
model.PopulatePagingTo(prmAssociation.ResultsPaging);
|
||||
|
||||
// Item columns.
|
||||
ColumnDfn colId = AccountMgr.GetAssociationColumnDfn(SbmAssociation.Column.Id);
|
||||
ColumnDfn colAffIdTarget = AccountMgr.GetAssociationColumnDfn(SbmAssociation.Column.AffIdTarget);
|
||||
ColumnDfn colTargetName = AccountMgr.GetAssociationColumnDfn(SbmAssociation.Column.Target_Name);
|
||||
ColumnDfn colAssociationType = AccountMgr.GetAssociationColumnDfn(SbmAssociation.Column.Type_Desc);
|
||||
ColumnDfn colCode = AccountMgr.GetAssociationColumnDfn(SbmAssociation.Column.Code);
|
||||
ColumnDfn colExtRef = AccountMgr.GetAssociationColumnDfn(SbmAssociation.Column.ExtRef);
|
||||
ColumnDfn colGroup = AccountMgr.GetAssociationColumnDfn(SbmAssociation.Column.Group);
|
||||
ColumnDfn colDescDetail = AccountMgr.GetAssociationColumnDfn(SbmAssociation.Column.DescDetail);
|
||||
ColumnDfn colNotes = AccountMgr.GetAssociationColumnDfn(SbmAssociation.Column.Notes);
|
||||
ColumnDfn colStatus = AccountMgr.GetAssociationColumnDfn(SbmAssociation.Column.Status);
|
||||
ColumnDfn colCreatedOn = AccountMgr.GetAssociationColumnDfn(SbmAssociation.Column.CreateOn_Date);
|
||||
ColumnDfn colUpdatedOn = AccountMgr.GetAssociationColumnDfn(SbmAssociation.Column.UpdateOn_Date);
|
||||
List<ColumnDfn> columns = new List<ColumnDfn>()
|
||||
{
|
||||
colId, colAffIdTarget, colTargetName, colAssociationType,
|
||||
colCode, colExtRef, colGroup, colDescDetail,
|
||||
colNotes, colStatus, colCreatedOn, colUpdatedOn
|
||||
};
|
||||
|
||||
// Query items.
|
||||
using (DbResultSet resultSet = AccountMgr.ExecuteAssociationQuery(columns, prmAssociation))
|
||||
{
|
||||
while (resultSet != null && resultSet.HasRows && resultSet.NextRecord())
|
||||
{
|
||||
NamedValue.Map values = resultSet.GetRecordValues();
|
||||
Sbm.AssociationType associationType = (Sbm.AssociationType)values.GetLong(colAssociationType.DataName);
|
||||
AssociationData_List associationData = new AssociationData_List()
|
||||
{
|
||||
Id = values.GetString(colId.DataName),
|
||||
TargetId = values.GetString(colAffIdTarget.DataName),
|
||||
TargetName = values.GetString(colTargetName.DataName),
|
||||
TypeCode = Internals.AssociationTypeCodes.GetCodeForType(associationType),
|
||||
TypeDesc = Internals.AssociationTypeCodes.GetDescForType(associationType),
|
||||
Code = values.GetString(colCode.DataName),
|
||||
ReferenceExt = values.GetString(colExtRef.DataName),
|
||||
Group = values.GetString(colGroup.DataName),
|
||||
DescDetail = values.GetString(colDescDetail.DataName),
|
||||
Notes = values.GetString(colNotes.DataName),
|
||||
StatusCode = values.GetString(colStatus.DataName),
|
||||
StatusDesc = SacsSystem.GetStatusDescForCode(values.GetString(colStatus.DataName)),
|
||||
CreatedOn = DateUtil.Format(values.GetDate(colCreatedOn.DataName), "yyyyMMdd"),
|
||||
CreatedOnFmt = Localiser.FormatDate(values.GetDate(colCreatedOn.DataName)),
|
||||
UpdatedOn = DateUtil.Format(values.GetDate(colUpdatedOn.DataName), "yyyyMMdd"),
|
||||
UpdatedOnFmt = Localiser.FormatDate(values.GetDate(colUpdatedOn.DataName))
|
||||
};
|
||||
responseData.Associations.Add(associationData);
|
||||
}
|
||||
}
|
||||
|
||||
// Refresh paging info.
|
||||
if (model.Paging.IsPaged)
|
||||
model.Paging.ItemCount = (ushort)responseData.Associations.Count;
|
||||
SessionData_Portal.Profile.Associations.Filter.PageNo = model.Paging.PageNo;
|
||||
SessionData_Portal.Profile.Associations.Filter.PageLength = model.Paging.PageLength;
|
||||
responseData.SetPaging(model);
|
||||
|
||||
// Complete response.
|
||||
responseData.Success = true;
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get Association ajax request.
|
||||
//-------------------------------------------------------------------
|
||||
private class AjaxResponse_Association : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_Association(SbmModel_Portal model) : base(model) { }
|
||||
// Association details.
|
||||
public AssociationData_Full association { get; } = new AssociationData_Full();
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
[HttpPost]
|
||||
[Route("Association/Ajax/Item")]
|
||||
[Route("Association/Ajax/GetItem")]
|
||||
public IActionResult Ajax_GetItem(Model_Association model)
|
||||
{
|
||||
String fn = GetType().Name + ".Ajax_GetItem";
|
||||
String messageTitle = Localiser["association.caption.association"];
|
||||
AjaxResponse_Association responseData = new AjaxResponse_Association(model);
|
||||
|
||||
// Validate session and referrer.
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
if (!ValidReferer) return Forbid();
|
||||
RefreshModel(model);
|
||||
|
||||
// Identify item.
|
||||
SysId associationId = model.AssociationId.ToSysId();
|
||||
if (!SysId.IsValid(associationId))
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.specified"]));
|
||||
|
||||
// Retrieve item.
|
||||
SbmAssociation association = AccountMgr.GetAssociationById(associationId);
|
||||
if (association == null)
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve association for Id: '" + model.AssociationId + "'");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"]));
|
||||
}
|
||||
|
||||
// Construct response.
|
||||
PopulateAssociationResponseData(association, responseData.association);
|
||||
|
||||
// Complete response.
|
||||
responseData.Success = true;
|
||||
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Store Association ajax request.
|
||||
//-------------------------------------------------------------------
|
||||
[HttpPost]
|
||||
[Route("Association/Ajax/Store")]
|
||||
[Route("Association/Ajax/StoreItem")]
|
||||
public IActionResult Ajax_StoreItem(Model_Association model)
|
||||
{
|
||||
String fn = GetType().Name + ".Ajax_StoreItem";
|
||||
String messageTitle = Localiser["association.caption.association"];
|
||||
AjaxResponse_Association responseData = new AjaxResponse_Association(model);
|
||||
|
||||
// Validate session and referrer.
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
if (!ValidReferer) return Forbid();
|
||||
RefreshModel(model);
|
||||
|
||||
// Validate item properties.
|
||||
model.ValidateAssociationData(responseData);
|
||||
if (responseData.HasControlErrors())
|
||||
return Json(responseData);
|
||||
|
||||
// Validate item Id against 'Exists' flag.
|
||||
SysId associationId = model.AssociationId.ToSysId();
|
||||
bool associationExists = StringUtil.ToBool(model.AssociationExists);
|
||||
if (associationExists && !SysId.IsValid(associationId))
|
||||
{
|
||||
SaLogger.Warn(fn + " Id not specified for existing Association.");
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
if (!associationExists && SysId.IsValid(associationId))
|
||||
{
|
||||
SaLogger.Warn(fn + " Id specified for new Association: '" + model.AssociationId + "'");
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
|
||||
// Retrieve existing item.
|
||||
SbmAssociation association = AccountMgr.GetAssociationById(associationId);
|
||||
if (association == null && SysId.IsValid(associationId))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve association for Id: '" + model.AssociationId + "'");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"]));
|
||||
}
|
||||
|
||||
// Create new item if required.
|
||||
if (association == null)
|
||||
{
|
||||
association = AccountMgr.CreateAssociation(SessionData.Organisation.AffiliateId, model.GetAssociationType(), model.AffiliateIdTarget.ToSysId());
|
||||
}
|
||||
|
||||
// Populate item properties.
|
||||
if (model.AssociationCode != null)
|
||||
association.Code = model.AssociationCode;
|
||||
if (model.AssociationReferenceExt != null)
|
||||
association.RefExt = model.AssociationReferenceExt;
|
||||
if (model.AssociationLocation != null)
|
||||
association.Location = model.AssociationLocation;
|
||||
if (model.AssociationRole != null)
|
||||
association.Role = model.AssociationRole;
|
||||
if (model.AssociationPhoneMain != null)
|
||||
association.PhoneMain = model.AssociationPhoneMain;
|
||||
if (model.AssociationEmail != null)
|
||||
association.Email = model.AssociationEmail;
|
||||
if (model.AssociationGroup != null)
|
||||
association.Group = model.AssociationGroup;
|
||||
if (model.AssociationDescDetail != null)
|
||||
association.DescDetail = model.AssociationDescDetail;
|
||||
if (model.AssociationNominalCodeDefault != null)
|
||||
association.DefaultNominalCode = model.AssociationNominalCodeDefault;
|
||||
// Account.
|
||||
if (model.AssociationAccountManagerCode != null)
|
||||
association.AccountManagerCode = model.AssociationAccountManagerCode;
|
||||
if (model.AssociationAccountHandlerCode != null)
|
||||
association.AccountHandlerCode = model.AssociationAccountHandlerCode;
|
||||
if (model.AssociationAccountTypeCode != null)
|
||||
association.AccountTypeCode = model.AssociationAccountTypeCode;
|
||||
if (model.AssociationAccountRatingCode != null)
|
||||
association.AccountRatingCode = model.AssociationAccountRatingCode;
|
||||
// Contact.
|
||||
if (model.AssociationContactAreaCode != null)
|
||||
association.ContactAreaCode = model.AssociationContactAreaCode;
|
||||
if (model.AssociationContactHandlerCode != null)
|
||||
association.ContactHandlerCode = model.AssociationContactHandlerCode;
|
||||
if (model.AssociationContactMethodCode != null)
|
||||
association.ContactMethodCode = model.AssociationContactMethodCode;
|
||||
if (model.AssociationContactCallCycleCode != null)
|
||||
association.ContactCallCycleCode = model.AssociationContactCallCycleCode;
|
||||
if (model.AssociationCallsPerYear != null)
|
||||
association.CallsPerYear = StringUtil.ToInt(model.AssociationCallsPerYear);
|
||||
if (model.AssociationLastCallDate != null)
|
||||
association.LastCall = model.ParseDateFromForm(model.AssociationLastCallDate);
|
||||
// Customer.
|
||||
if (model.AssociationCommodityIdSalesDefault != null)
|
||||
association.CommodityIdSalesDefault = model.AssociationCommodityIdSalesDefault.ToSysId();
|
||||
if (model.AssociationOrderLeadTimeCode != null)
|
||||
association.OrderLeadTimeCode = model.AssociationOrderLeadTimeCode;
|
||||
if (model.AssociationDeliveryTypeCode != null)
|
||||
association.DeliveryTypeCode = model.AssociationDeliveryTypeCode;
|
||||
if (model.AssociationDeliveryMethodCode != null)
|
||||
association.DeliveryMethodCode = model.AssociationDeliveryMethodCode;
|
||||
if (model.AssociationDeliveryCourierCode != null)
|
||||
association.DeliveryCourierCode = model.AssociationDeliveryCourierCode;
|
||||
if (model.AssociationDeliveryBookInCode != null)
|
||||
association.DeliveryBookInCode = model.AssociationDeliveryBookInCode;
|
||||
// Transactions.
|
||||
if (model.AssociationAmountTransMax != null)
|
||||
association.AmountTransMax = StringUtil.ToDecimal(model.AssociationAmountTransMax);
|
||||
if (model.AssociationAnnualSalesTarget != null)
|
||||
association.AnnualSalesTarget = StringUtil.ToDecimal(model.AssociationAnnualSalesTarget);
|
||||
if (model.AssociationCreditLimit != null)
|
||||
association.CreditLimit = StringUtil.ToDecimal(model.AssociationCreditLimit);
|
||||
if (model.AssociationAccountBalance != null)
|
||||
association.AccountBalance = StringUtil.ToDecimal(model.AssociationAccountBalance);
|
||||
if (model.AssociationDiscountType != null)
|
||||
association.DiscountType = model.GetAssociationDiscountType();
|
||||
if (model.AssociationDiscountRate != null)
|
||||
association.DiscountRate = StringUtil.ToDecimal(model.AssociationDiscountRate);
|
||||
if (model.AssociationPriceSetId != null)
|
||||
association.PriceSetId = model.AssociationPriceSetId.ToSysId();
|
||||
if (model.AssociationTaxCodeId != null)
|
||||
association.TaxCodeId = model.AssociationTaxCodeId.ToSysId();
|
||||
if (model.AssociationPaymentTerms != null)
|
||||
association.PaymentTerms = StringUtil.ToShort(model.AssociationPaymentTerms);
|
||||
if (model.AssociationInvoiceDesc != null)
|
||||
association.InvoiceDesc = model.AssociationInvoiceDesc;
|
||||
if (model.AssociationTerminatedDate != null)
|
||||
association.Terminated = model.ParseDateFromForm(model.AssociationTerminatedDate);
|
||||
// Common properties.
|
||||
if (model.AssociationNotes != null)
|
||||
association.Notes = model.AssociationNotes;
|
||||
if (model.AssociationStatusCode != null)
|
||||
association.Status = model.AssociationStatus;
|
||||
|
||||
// Store item.
|
||||
if (!SysId.IsValid(association.Id))
|
||||
{
|
||||
if (!AccountMgr.InsertAssociation(association, DbUpdateInfo))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to insert association: " + 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
|
||||
{
|
||||
if (!AccountMgr.UpdateAssociation(association, DbUpdateInfo))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to update association [Id:" + SysId.ToString(association.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.
|
||||
PopulateAssociationResponseData(association, responseData.association);
|
||||
|
||||
// Complete response.
|
||||
responseData.Success = true;
|
||||
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
Reference in New Issue
Block a user