/// <summary>
        /// Maps CasualActivity EF object to CasualActivity Model Object and
        /// returns the CasualActivity model object.
        /// </summary>
        /// <param name="result">EF CasualActivity object to be mapped.</param>
        /// <returns>CasualActivity Model Object.</returns>
        public CasualActivity MapEFToModel(EF.Models.CasualActivity data)
        {
            string casualName = string.Empty;

            if (data.CasualWorker != null)
            {
                casualName = data.CasualWorker.FirstName + " " + data.CasualWorker.LastName;
            }

            var casualActivity = new CasualActivity()
            {
                CasualActivityId = data.CasualActivityId,
                Amount           = data.Amount,
                SectorId         = data.SectorId,
                BranchId         = data.BranchId,
                BatchId          = data.BatchId,
                Notes            = data.Notes,
                BatchNumber      = data.Batch != null? data.Batch.Name:"",
                Quantity         = data.Quantity,
                ActivityId       = data.ActivityId,
                ActivityName     = data.Activity != null ? data.Activity.Name : "",
                CasualWorkerId   = data.CasualWorkerId,
                CasualWorkerName = casualName,
                BranchName       = data.Branch != null ? data.Branch.Name : "",
                SectorName       = data.Sector != null ? data.Sector.Name : "",
                CreatedOn        = data.CreatedOn,
                TimeStamp        = data.TimeStamp,
                Deleted          = data.Deleted,
                CreatedBy        = _userService.GetUserFullName(data.AspNetUser),
                UpdatedBy        = _userService.GetUserFullName(data.AspNetUser1),
            };

            return(casualActivity);
        }
Esempio n. 2
0
        /// <summary>
        /// Saves a new CasualActivity or updates an already existing CasualActivity.
        /// </summary>
        /// <param name="CasualActivity">CasualActivity to be saved or updated.</param>
        /// <param name="CasualActivityId">CasualActivityId of the CasualActivity creating or updating</param>
        /// <returns>CasualActivityId</returns>
        public long SaveCasualActivity(CasualActivityDTO casualActivityDTO, string userId)
        {
            long casualActivityId = 0;

            if (casualActivityDTO.CasualActivityId == 0)
            {
                var casualActivity = new CasualActivity()
                {
                    Quantity       = casualActivityDTO.Quantity,
                    Amount         = casualActivityDTO.Amount,
                    CasualWorkerId = casualActivityDTO.CasualWorkerId,
                    ActivityId     = casualActivityDTO.ActivityId,
                    BranchId       = casualActivityDTO.BranchId,
                    Notes          = casualActivityDTO.Notes,
                    SectorId       = casualActivityDTO.SectorId,
                    BatchId        = casualActivityDTO.BatchId,
                    CreatedOn      = DateTime.Now,
                    TimeStamp      = DateTime.Now,
                    CreatedBy      = userId,
                    Deleted        = false,
                };

                this.UnitOfWork.Get <CasualActivity>().AddNew(casualActivity);
                this.UnitOfWork.SaveChanges();
                casualActivityId = casualActivity.CasualActivityId;
                return(casualActivityId);
            }

            else
            {
                var result = this.UnitOfWork.Get <CasualActivity>().AsQueryable()
                             .FirstOrDefault(e => e.CasualActivityId == casualActivityDTO.CasualActivityId);
                if (result != null)
                {
                    result.Amount         = casualActivityDTO.Amount;
                    result.UpdatedBy      = userId;
                    result.ActivityId     = casualActivityDTO.ActivityId;
                    result.CasualWorkerId = casualActivityDTO.CasualWorkerId;
                    result.BatchId        = casualActivityDTO.BatchId;
                    result.Notes          = casualActivityDTO.Notes;
                    result.TimeStamp      = DateTime.Now;
                    result.Deleted        = casualActivityDTO.Deleted;
                    result.BranchId       = casualActivityDTO.BranchId;
                    result.SectorId       = casualActivityDTO.SectorId;
                    result.DeletedBy      = casualActivityDTO.DeletedBy;
                    result.DeletedOn      = casualActivityDTO.DeletedOn;
                    result.Quantity       = casualActivityDTO.Quantity;

                    this.UnitOfWork.Get <CasualActivity>().Update(result);
                    this.UnitOfWork.SaveChanges();
                }
                return(casualActivityDTO.CasualActivityId);
            }
            return(casualActivityId);
        }
        public long SaveCasualActivity(CasualActivity casualActivity, string userId)
        {
            var casualActivityDTO = new DTO.CasualActivityDTO()
            {
                CasualActivityId = casualActivity.CasualActivityId,
                BatchId          = casualActivity.BatchId,
                CasualWorkerId   = casualActivity.CasualWorkerId,
                Quantity         = casualActivity.Quantity,
                ActivityId       = casualActivity.ActivityId,
                BranchId         = casualActivity.BranchId,
                Amount           = casualActivity.Amount,
                Notes            = casualActivity.Notes,
                Deleted          = casualActivity.Deleted,
                CreatedBy        = casualActivity.CreatedBy,
                CreatedOn        = casualActivity.CreatedOn,
                SectorId         = casualActivity.SectorId,
            };

            var casualActivityId = this._dataService.SaveCasualActivity(casualActivityDTO, userId);

            var activityBatchCasualDTO = new DTO.ActivityBatchCasualDTO()
            {
                CasualWorkerId = casualActivity.CasualWorkerId,
                BatchId        = casualActivity.BatchId,
                ActivityId     = casualActivity.ActivityId,
                Amount         = casualActivity.Amount,
                CreatedBy      = userId,
            };

            this._dataService.SaveActivityBatchCasual(activityBatchCasualDTO, userId);

            var accountActivityDTO = new AccountTransactionActivity()
            {
                TransactionSubTypeId = casualActivity.TransactionSubTypeId,
                Action         = casualActivity.Action,
                Amount         = casualActivity.Amount,
                Notes          = casualActivity.Notes,
                CasualWorkerId = casualActivity.CasualWorkerId,
                BranchId       = casualActivity.BranchId,
                SectorId       = casualActivity.SectorId,
                Deleted        = casualActivity.Deleted,
                CreatedBy      = casualActivity.CreatedBy,
                CreatedOn      = Convert.ToDateTime(casualActivity.CreatedOn)
            };
            var accountActivityId = _accountTransactionActivityService.SaveAccountTransactionActivity(accountActivityDTO, userId);

            return(casualActivityId);
        }
        public long Save(CasualActivity model)
        {
            var casualActivityId = _casualActivityService.SaveCasualActivity(model, userId);

            return(casualActivityId);
        }