Пример #1
0
        /// <summary>
        /// Created By : Ashwajit Bansod
        /// Created Date : 17-OCT-2018
        /// Created For : To save Miscellaneous data
        /// </summary>
        /// <param name="Obj"></param>
        /// <returns></returns>
        public ServiceResponseModel <MiscellaneousDetails> SaveMiscellaneous(MiscellaneousDetails Obj)
        {
            bool          IsSaved       = false;
            string        Action        = "";
            var           objDAR        = new DARModel();
            List <string> LocationData  = new List <string>();
            var           CommonManager = new CommonMethodManager();
            string        MISID         = "";
            string        LocationName  = "";
            long          UserId        = 0;
            long          Mis_Id        = 0;
            decimal       TotalAmount   = 0;

            try
            {
                var data = new MiscellaneousDetails();
                var ObjServiceResponseModel = new ServiceResponseModel <MiscellaneousDetails>();
                if (Obj.MiscellaneousDetailsmodel.Count > 0)
                {
                    Action = "I";
                    foreach (var item in Obj.MiscellaneousDetailsmodel)
                    {
                        var SaveMiscData = _workorderems.spSetMiscellaneous(Action, item.MISId, item.CostCode, item.LocationId,
                                                                            item.VendorId, item.Discription, item.InvoiceAmount,
                                                                            item.InvoiceDate, item.InvoiceDocument, item.UserId,
                                                                            null, "Y");
                        var locData = _workorderems.LocationMasters.Where(x => x.LocationId == item.LocationId && x.IsDeleted == false).FirstOrDefault();
                        LocationData.Add(locData.LocationName);
                        MISID        = "MIS" + item.MISId.ToString();
                        Mis_Id       = item.MISId;
                        UserId       = item.UserId;
                        TotalAmount += Convert.ToDecimal(item.InvoiceAmount);
                        IsSaved      = true;
                    }

                    if (IsSaved == true)
                    {
                        ObjServiceResponseModel.Response = Convert.ToInt32(ServiceResponse.SuccessResponse, CultureInfo.CurrentCulture);
                        ObjServiceResponseModel.Message  = CommonMessage.SaveSuccessMessage();
                        ObjServiceResponseModel.Data     = null;
                    }
                    else
                    {
                        ObjServiceResponseModel.Response = Convert.ToInt32(ServiceResponse.NoRecord, CultureInfo.CurrentCulture);
                        ObjServiceResponseModel.Message  = CommonMessage.NoRecordMessage();
                        ObjServiceResponseModel.Data     = null;
                    }
                    #region Save DAR
                    LocationName           = string.Join(",", LocationData.ToArray());
                    objDAR.ActivityDetails = DarMessage.MiscellaneousCreated(LocationName, MISID);
                    objDAR.TaskType        = (long)TaskTypeCategory.MiscellaneousCreated;
                    objDAR.UserId          = UserId;
                    objDAR.CreatedBy       = UserId;
                    objDAR.CreatedOn       = DateTime.UtcNow;
                    CommonManager.SaveDAR(objDAR);
                    #endregion DAR


                    #region Notification
                    var objNotify      = new NotificationDetailModel();
                    var _ICommonMethod = new CommonMethodManager();
                    var objModel       = new CommonApproval <ApprovalInput>();
                    var approvalInput  = new ApprovalInput();
                    approvalInput.Amount     = TotalAmount;
                    approvalInput.UserId     = UserId;
                    approvalInput.ModuleName = "eCounting";
                    var getRuleData = objModel.GetApprovalRuleData(approvalInput);
                    if (getRuleData != null)
                    {
                        objNotify.CreatedBy   = UserId;
                        objNotify.CreatedDate = DateTime.UtcNow;
                        objNotify.AssignTo    = getRuleData.UserId;
                        if (MISID != null)
                        {
                            //var id = Convert.ToInt64(MISID);
                            objNotify.MiscellaneousID = Mis_Id;
                        }
                        var saveDataForNotification = _ICommonMethod.SaveNotificationDetail(objNotify);
                    }
                    if (getRuleData.DeviceId != null)
                    {
                        var objEmailHelper   = new EmailHelper();
                        var objTemplateModel = new TemplateModel();
                        var userData         = _workorderems.UserRegistrations.Where(x => x.UserId == UserId &&
                                                                                     x.IsDeleted == false && x.IsEmailVerify == true).FirstOrDefault();
                        objEmailHelper.emailid      = getRuleData.Email;
                        objEmailHelper.ManagerName  = getRuleData.ManagerName;
                        objEmailHelper.LocationName = LocationName;
                        if (userData != null)
                        {
                            objEmailHelper.UserName = userData.FirstName + " " + userData.LastName;
                        }
                        objEmailHelper.MISId = MISID;
                        //objEmailHelper.InfractionStatus = obj.Status;
                        objEmailHelper.MailType      = "APPROVEMISCELLANEOUS";
                        objEmailHelper.SentBy        = UserId;
                        objEmailHelper.LocationID    = objDAR.LocationId;
                        objEmailHelper.TimeAttempted = DateTime.UtcNow.ToMobileClientTimeZone(objTemplateModel.TimeZoneName, objTemplateModel.TimeZoneOffset, objTemplateModel.IsTimeZoneinDaylight, false).ToString();
                        objEmailHelper.IsWorkable    = true;
                        if (getRuleData.DeviceId != null)
                        {
                            string message = PushNotificationMessages.MiscellaneousCreate(objNotify.BillID.ToString(), objEmailHelper.UserName, objEmailHelper.LocationName);
                            PushNotificationFCM.FCMAndroid(message, getRuleData.DeviceId, objEmailHelper);
                        }
                    }
                    #endregion Notification

                    return(ObjServiceResponseModel);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Exception_B.Exception_B.exceptionHandel_Runtime(ex, "public ServiceResponseModel<miscellaneousNumberModel> GetMiscellaneousNumberData(ServiceBaseModel ObjServiceBaseModel)", "Exception While Getting Miscellaneous number.", null);
                throw;
            }
        }