private Guid AddNewRevenueAndUpdateContractModRevenueGuid(ContractModification model)
        {
            Guid revenueRecognitionGuid = Guid.NewGuid();
            bool isSaved = _revenueRecognitionService.AddRevenueWithResourceGuid(
                new RevenueRecognition
            {
                RevenueRecognizationGuid = revenueRecognitionGuid,
                ResourceGuid             = model.ContractModificationGuid,
                ContractGuid             = model.ContractGuid,
                UpdatedBy = model.UpdatedBy,
                UpdatedOn = model.UpdatedOn,
                CreatedBy = model.UpdatedBy,
                CreatedOn = model.UpdatedOn
            });

            if (isSaved)
            {
                _contractService.InsertRevenueRecognitionGuid(revenueRecognitionGuid, model.ContractGuid);
                _contractModificationService.InsertRevenueRecognitionGuid(revenueRecognitionGuid, model.ContractGuid);
                AddNotificationMessage(model);
                return(revenueRecognitionGuid);
            }
            return(Guid.Empty);
        }
Esempio n. 2
0
        public ActionResult SaveRevenueRecognition(RevenueRecognitionViewModel model)
        {
            try
            {
                var    loggedUser        = new Guid(HttpContext.User.Identity.Name);
                string userName          = "";
                var    loggedUserDetails = _userService.GetUserByUserGuid(loggedUser);
                if (loggedUserDetails != null)
                {
                    userName = loggedUserDetails.DisplayName;
                }
                DateTime currentdatetime             = CurrentDateTimeHelper.GetCurrentDateTime();
                string   date                        = currentdatetime.ToString("MM/dd/yyyy");
                var      recognitionEntity           = _mapper.Map <RevenueRecognition>(model);
                var      contractExtensionEntityList = _mapper.Map <List <RevenueContractExtension> >(model.ListContractExtension);
                var      obligationEntityList        = _mapper.Map <List <RevenuePerformanceObligation> >(model.ListRevenuePerformanceObligation);
                switch (model.CrudType)
                {
                case CrudType.Create:
                    recognitionEntity.CreatedOn = currentdatetime;
                    recognitionEntity.CreatedBy = loggedUser;
                    recognitionEntity.UpdatedOn = currentdatetime;
                    recognitionEntity.UpdatedBy = loggedUser;
                    recognitionEntity.IsActive  = true;
                    recognitionEntity.IsDeleted = false;
                    model.CrudType = CrudType.Edit;
                    _revenueRecognitionService.UpdateRevenueRecognition(recognitionEntity);

                    //audit log..
                    var additionalInformation    = string.Format("{0} {1} the {2}", User.FindFirst("fullName").Value, CrudTypeForAdditionalLogMessage.Added.ToString(), "Revenue Recognition");
                    var additionalInformationURl = _configuration.GetSection("SiteUrl").Value + ("/Contract/Details/" + recognitionEntity.ContractGuid);
                    var resource = string.Format("{0} </br> GUID:{1}", "Revenue Recognition", recognitionEntity.RevenueRecognizationGuid);
                    AuditLogHandler.InfoLog(_logger, User.FindFirst("fullName").Value, UserHelper.CurrentUserGuid(HttpContext), recognitionEntity, resource, recognitionEntity.RevenueRecognizationGuid, UserHelper.GetHostedIp(HttpContext), "Revenue Recognition Added", Guid.Empty, "Successful", "", additionalInformationURl, additionalInformationURl);
                    //end of log..

                    return(Ok(new { model.CrudType, updatedby = userName, updatedon = date, revenueGuid = recognitionEntity.RevenueRecognizationGuid, isnotify = false, CurrentStage = model.CurrentStage, contractGuid = model.ContractGuid }));

                case CrudType.Edit:
                    var recognitionEntitydata = _revenueRecognitionService.GetDetailsById(model.RevenueRecognizationGuid);
                    recognitionEntity.CreatedBy = recognitionEntitydata.CreatedBy;
                    recognitionEntity.CreatedOn = recognitionEntitydata.CreatedOn;
                    recognitionEntity.UpdatedBy = loggedUser;
                    recognitionEntity.UpdatedOn = currentdatetime;
                    if (!CheckAuthorization(recognitionEntity.ContractGuid, model.IsAccountRepresentive))
                    {
                        throw new Exception("Not an authorized user!!");
                    }
                    switch (model.CurrentStage)
                    {
                    case "#tab_5":
                        recognitionEntity.IsNotify    = true;
                        recognitionEntity.IsCompleted = true;
                        _contractRefactorService.InsertRevenueRecognitionGuid(recognitionEntity.RevenueRecognizationGuid, recognitionEntity.ContractGuid);
                        _contractModificationService.InsertRevenueRecognitionGuid(recognitionEntity.RevenueRecognizationGuid, recognitionEntity.ContractGuid);
                        break;

                    case "#tab_4":
                        var notificationbatch = _notificationBatchService.GetByResourceId(recognitionEntity.RevenueRecognizationGuid);
                        if (notificationbatch == null)
                        {
                            SaveAndNotifyAccountingRepresentative(recognitionEntity);
                        }
                        recognitionEntity.IsNotify = true;
                        _revenueRecognitionService.UpdateIsNotify(recognitionEntity.RevenueRecognizationGuid);
                        break;
                    }
                    _revenueRecognitionService.UpdateRevenueRecognition(recognitionEntity);

                    //audit log..
                    if (!string.IsNullOrEmpty(model.CurrentStage))
                    {
                        if (model.CurrentStage.Equals("#tab_5") || model.CurrentStage.Equals("#tab_4"))
                        {
                            additionalInformation    = string.Format("{0} {1} the {2}", User.FindFirst("fullName").Value, CrudTypeForAdditionalLogMessage.Edited.ToString(), "Revenue Recognition");
                            additionalInformationURl = _configuration.GetSection("SiteUrl").Value + ("/Contract/Details/" + recognitionEntity.ContractGuid);
                            resource = string.Format("{0} </br> GUID:{1}", "Revenue Recognition", recognitionEntity.RevenueRecognizationGuid);
                            AuditLogHandler.InfoLog(_logger, User.FindFirst("fullName").Value, UserHelper.CurrentUserGuid(HttpContext), recognitionEntity, resource, recognitionEntity.RevenueRecognizationGuid, UserHelper.GetHostedIp(HttpContext), "Revenue Recognition Edited", Guid.Empty, "Successful", "", additionalInformationURl, additionalInformationURl);
                        }
                    }
                    //end of log..

                    if (recognitionEntity.IsContractTermExpansion)
                    {
                        SaveContractExtension(contractExtensionEntityList, recognitionEntity.RevenueRecognizationGuid);
                    }
                    SaveObligationEntity(obligationEntityList, recognitionEntity.RevenueRecognizationGuid);
                    return(Ok(new { model.CrudType, revenueGuid = model.RevenueRecognizationGuid, updatedby = userName, updatedon = date, isnotify = true, CurrentStage = model.CurrentStage, contractGuid = model.ContractGuid }));
                }
                return(Ok(new { status = ResponseStatus.success.ToString(), message = "Successfully Added !!", model.CrudType }));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(BadRequest(ModelState));
            }
        }