public PrqPurchaseYearPeriod SetToBussinessObject(Prq_PurchaseYearPeriod Entity)
        {
            PrqPurchaseYearPeriod Model = new PrqPurchaseYearPeriod();

            Model.PeriodID   = Entity.PeriodID;
            Model.PeriodName = GetShortMonthName(Entity.StartDate.Month) + "-" + GetShortMonthName(Entity.EndDate.Month);

            return(Model);
        }
Beispiel #2
0
        public PrqPurchaseYearPeriod SetToBussinessObject(Prq_PurchaseYearPeriod Entity)
        {
            PrqPurchaseYearPeriod Model = new PrqPurchaseYearPeriod();

            Model.PeriodID     = Entity.PeriodID;
            Model.YearID       = Entity.YearID;
            Model.StartDate    = Entity.StartDate.ToString("dd/MM/yyyy");
            Model.EndDate      = Entity.EndDate.ToString("dd/MM/yyyy");
            Model.RecordStatus = Entity.RecordStatus;
            return(Model);
        }
Beispiel #3
0
        public Prq_PurchaseYearPeriod SetToModelObject(PrqPurchaseYearPeriod model)
        {
            Prq_PurchaseYearPeriod Entity = new Prq_PurchaseYearPeriod();

            Entity.StartDate    = DalCommon.SetDate(model.StartDate); // Convert.ToDateTime(Convert.ToDateTime(model.StartDate).ToString("dd/MM/yyyy"));
            Entity.EndDate      = DalCommon.SetDate(model.EndDate);   // Convert.ToDateTime(Convert.ToDateTime(model.EndDate).ToString("dd/MM/yyyy"));
            Entity.YearID       = model.YearID;
            Entity.RecordStatus = "NCF";
            Entity.SetOn        = DateTime.Now;
            Entity.SetBy        = model.SetBy;

            return(Entity);
        }
        public Prq_PurchaseYearPeriod SetToModelObject(PrqPurchaseYearPeriod model)
        {
            Prq_PurchaseYearPeriod Entity = new Prq_PurchaseYearPeriod();

            Entity.StartDate    = Convert.ToDateTime(Convert.ToDateTime(model.StartDate).ToString("dd/MM/yyyy"));
            Entity.EndDate      = Convert.ToDateTime(Convert.ToDateTime(model.EndDate).ToString("dd/MM/yyyy"));
            Entity.YearID       = Convert.ToInt16(_context.Prq_PurchaseYearTarget.DefaultIfEmpty().Max(m => m.YearID == null ? 0 : m.YearID));
            Entity.RecordStatus = "12";
            Entity.SetOn        = DateTime.Now;
            Entity.SetBy        = Convert.ToInt32(25);
            Entity.ModifiedOn   = DateTime.Now;
            Entity.ModifiedBy   = Convert.ToInt32(25);
            Entity.IPAddress    = string.Empty;

            return(Entity);
        }
Beispiel #5
0
        public ValidationMsg Save(PrqPurchaseYearTarget model, int userid)
        {
            _vmMsg = new ValidationMsg();
            try
            {
                IList <string> periodlist = new List <string>();
                periodlist.Add(model.YearStartDate);
                foreach (var period in model.PeriodList)
                {
                    periodlist.Add(period.StartDate.Contains("/") ? period.StartDate : Convert.ToDateTime(period.StartDate).ToString("dd/MM/yyyy"));
                    periodlist.Add(period.EndDate.Contains("/") ? period.EndDate : Convert.ToDateTime(period.EndDate).ToString("dd/MM/yyyy"));
                }

                for (int i = 1; i <= periodlist.Count - 1; i++)
                {
                    double day = (DalCommon.SetDate(periodlist[i]) - DalCommon.SetDate(periodlist[i - 1])).TotalDays;
                    if (i != 1)
                    {
                        if (day <= 0)
                        {
                            error = 1;
                            break;
                        }
                    }
                }
                if (error == 0)
                {
                    #region Save

                    using (var tx = new TransactionScope())
                    {
                        using (_context)
                        {
                            var exitData = _context.Prq_PurchaseYearTarget.Where(m => m.PurchaseYear == model.PurchaseYear).ToList();
                            if (exitData.Count > 0)
                            {
                                _vmMsg.Type = Enums.MessageType.Error;
                                _vmMsg.Msg  = "Alreary Exit This Year.";
                            }
                            else
                            {
                                model.SetBy = userid;
                                Prq_PurchaseYearTarget tblPurchaseYearTarget = SetToModelObject(model);
                                _context.Prq_PurchaseYearTarget.Add(tblPurchaseYearTarget);
                                _context.SaveChanges();

                                #region Save Period Records

                                if (model.PurchaseYearPeriodList != null)
                                {
                                    foreach (PrqPurchaseYearPeriod objPrqPurchaseYearPeriod in model.PurchaseYearPeriodList)
                                    {
                                        ////var yearStartDate = Convert.ToDateTime(objPrqPurchaseYearPeriod.StartDate).Date;
                                        ////var yearEndDate = Convert.ToDateTime(objPrqPurchaseYearPeriod.EndDate).Date;
                                        //objPrqPurchaseYearPeriod.SetBy = userid;
                                        //objPrqPurchaseYearPeriod.StartDate =
                                        //    Convert.ToDateTime(objPrqPurchaseYearPeriod.StartDate)
                                        //        .Date.ToString("dd/MM/yyyy");
                                        //objPrqPurchaseYearPeriod.EndDate =
                                        //    Convert.ToDateTime(objPrqPurchaseYearPeriod.EndDate)
                                        //        .Date.ToString("dd/MM/yyyy");

                                        objPrqPurchaseYearPeriod.StartDate = objPrqPurchaseYearPeriod.StartDate.Contains("/") ? objPrqPurchaseYearPeriod.StartDate : Convert.ToDateTime(objPrqPurchaseYearPeriod.StartDate).ToString("dd/MM/yyyy");
                                        objPrqPurchaseYearPeriod.EndDate   = objPrqPurchaseYearPeriod.EndDate.Contains("/") ? objPrqPurchaseYearPeriod.EndDate : Convert.ToDateTime(objPrqPurchaseYearPeriod.EndDate).ToString("dd/MM/yyyy");
                                        objPrqPurchaseYearPeriod.YearID    = tblPurchaseYearTarget.YearID;
                                        Prq_PurchaseYearPeriod tblPurchaseYearPeriod =
                                            SetToModelObject(objPrqPurchaseYearPeriod);
                                        _context.Prq_PurchaseYearPeriod.Add(tblPurchaseYearPeriod);

                                        _context.SaveChanges();

                                        #region Save Period Item List

                                        if (model.PurchaseYearPeriodItemList != null)
                                        {
                                            foreach (
                                                PrqPurchaseYearPeriodItem objPrqPurchaseYearPeriodItem in
                                                model.PurchaseYearPeriodItemList)
                                            {
                                                objPrqPurchaseYearPeriodItem.PeriodID =
                                                    tblPurchaseYearPeriod.PeriodID;
                                                objPrqPurchaseYearPeriodItem.SetBy = userid;
                                                Prq_PurchaseYearPeriodItem tblPurchaseYearPeriodItem =
                                                    SetToModelObject(objPrqPurchaseYearPeriodItem);
                                                _context.Prq_PurchaseYearPeriodItem.Add(tblPurchaseYearPeriodItem);
                                            }
                                        }

                                        #endregion
                                    }
                                }
                                _context.SaveChanges();

                                #endregion

                                tx.Complete();
                                YearID      = tblPurchaseYearTarget.YearID;
                                _vmMsg.Type = Enums.MessageType.Success;
                                _vmMsg.Msg  = "Saved Successfully.";
                            }
                        }
                    }

                    #endregion
                }
                else
                {
                    _vmMsg.Type = Enums.MessageType.Error;
                    _vmMsg.Msg  = "Period is not Properly Define.";
                }
            }
            catch
            {
                _vmMsg.Type = Enums.MessageType.Error;
                _vmMsg.Msg  = "Failed to save.";
            }

            return(_vmMsg);
        }
Beispiel #6
0
        public ValidationMsg Update(PrqPurchaseYearTarget model, int userid)
        {
            _vmMsg = new ValidationMsg();
            try
            {
                IList <string> periodlist = new List <string>();
                periodlist.Add(model.YearStartDate);
                foreach (var period in model.PeriodList)
                {
                    periodlist.Add(period.StartDate.Contains("/") ? period.StartDate : Convert.ToDateTime(period.StartDate).ToString("dd/MM/yyyy"));
                    periodlist.Add(period.EndDate.Contains("/") ? period.EndDate : Convert.ToDateTime(period.EndDate).ToString("dd/MM/yyyy"));
                }

                for (int i = 1; i <= periodlist.Count - 1; i++)
                {
                    double day = (DalCommon.SetDate(periodlist[i]) - DalCommon.SetDate(periodlist[i - 1])).TotalDays;
                    if (day < 0)
                    {
                        error = 1;
                        break;
                    }
                }
                if (error == 0)
                {
                    #region Update

                    using (var tx = new TransactionScope())
                    {
                        using (_context)
                        {
                            Prq_PurchaseYearTarget CurrentEntity = SetToModelObject(model);
                            var OriginalEntity = _context.Prq_PurchaseYearTarget.First(m => m.YearID == model.YearID);

                            OriginalEntity.PurchaseYear  = CurrentEntity.PurchaseYear;
                            OriginalEntity.YearStartDate = CurrentEntity.YearStartDate;
                            OriginalEntity.YearEndDate   = CurrentEntity.YearEndDate;
                            OriginalEntity.ModifiedBy    = userid;
                            OriginalEntity.ModifiedOn    = DateTime.Now;

                            #region Save Period Records

                            if (model.PurchaseYearPeriodList != null)
                            {
                                foreach (PrqPurchaseYearPeriod objPrqPurchaseYearPeriod in model.PurchaseYearPeriodList)
                                {
                                    objPrqPurchaseYearPeriod.StartDate = objPrqPurchaseYearPeriod.StartDate.Contains("/") ? objPrqPurchaseYearPeriod.StartDate : Convert.ToDateTime(objPrqPurchaseYearPeriod.StartDate).ToString("dd/MM/yyyy");
                                    objPrqPurchaseYearPeriod.EndDate   = objPrqPurchaseYearPeriod.EndDate.Contains("/") ? objPrqPurchaseYearPeriod.EndDate : Convert.ToDateTime(objPrqPurchaseYearPeriod.EndDate).ToString("dd/MM/yyyy");

                                    //objPrqPurchaseYearPeriod.StartDate =
                                    //    Convert.ToDateTime(objPrqPurchaseYearPeriod.StartDate)
                                    //        .Date.ToString("dd/MM/yyyy");
                                    //objPrqPurchaseYearPeriod.EndDate =
                                    //    Convert.ToDateTime(objPrqPurchaseYearPeriod.EndDate)
                                    //        .Date.ToString("dd/MM/yyyy");

                                    if (objPrqPurchaseYearPeriod.PeriodID == 0)
                                    {
                                        objPrqPurchaseYearPeriod.YearID = model.YearID;
                                        objPrqPurchaseYearPeriod.SetBy  = userid;
                                        Prq_PurchaseYearPeriod tblPurchaseYearPeriod = SetToModelObject(objPrqPurchaseYearPeriod);
                                        _context.Prq_PurchaseYearPeriod.Add(tblPurchaseYearPeriod);
                                        PeriodID = tblPurchaseYearPeriod.PeriodID;
                                    }
                                    else
                                    {
                                        Prq_PurchaseYearPeriod CurEntity = SetToModelObject(objPrqPurchaseYearPeriod);
                                        var OrgEntity = _context.Prq_PurchaseYearPeriod.First(m => m.PeriodID == objPrqPurchaseYearPeriod.PeriodID);

                                        OrgEntity.StartDate  = CurEntity.StartDate;
                                        OrgEntity.EndDate    = CurEntity.EndDate;
                                        OrgEntity.ModifiedBy = userid;
                                        OrgEntity.ModifiedOn = DateTime.Now;
                                    }

                                    #region Save Period Item List

                                    if (model.PurchaseYearPeriodItemList != null)
                                    {
                                        foreach (
                                            PrqPurchaseYearPeriodItem objPrqPurchaseYearPeriodItem in
                                            model.PurchaseYearPeriodItemList)
                                        {
                                            if (objPrqPurchaseYearPeriodItem.PeriodItemID == 0)
                                            {
                                                objPrqPurchaseYearPeriodItem.PeriodID = PeriodID;
                                                objPrqPurchaseYearPeriodItem.SetBy    = userid;
                                                Prq_PurchaseYearPeriodItem tblPurchaseYearPeriodItem =
                                                    SetToModelObject(objPrqPurchaseYearPeriodItem);
                                                _context.Prq_PurchaseYearPeriodItem.Add(tblPurchaseYearPeriodItem);
                                            }
                                            else
                                            {
                                                Prq_PurchaseYearPeriodItem CurrEntity =
                                                    SetToModelObject(objPrqPurchaseYearPeriodItem);
                                                var OrgrEntity =
                                                    _context.Prq_PurchaseYearPeriodItem.First(
                                                        m =>
                                                        m.PeriodItemID ==
                                                        objPrqPurchaseYearPeriodItem.PeriodItemID);

                                                OrgrEntity.ItemTypeID     = CurrEntity.ItemTypeID;
                                                OrgrEntity.LeatherType    = CurrEntity.LeatherType;
                                                OrgrEntity.LeatherStatus  = CurrEntity.LeatherStatus;
                                                OrgrEntity.SizeID         = CurrEntity.SizeID;
                                                OrgrEntity.TargetQuantity = CurrEntity.TargetQuantity;
                                                OrgrEntity.UnitID         = CurrEntity.UnitID;
                                                OrgrEntity.TargetValue    = CurrEntity.TargetValue;
                                                OrgrEntity.CurrencyID     = CurrEntity.CurrencyID;
                                                OrgrEntity.RecordStatus   = CurrEntity.RecordStatus;
                                            }
                                        }
                                    }

                                    #endregion
                                }
                            }
                            else
                            {
                                #region Save Period Item List

                                if (model.PurchaseYearPeriodItemList != null)
                                {
                                    foreach (
                                        PrqPurchaseYearPeriodItem objPrqPurchaseYearPeriodItem in
                                        model.PurchaseYearPeriodItemList)
                                    {
                                        if (objPrqPurchaseYearPeriodItem.PeriodItemID == 0)
                                        {
                                            objPrqPurchaseYearPeriodItem.PeriodID = model.PeriodID;
                                            Prq_PurchaseYearPeriodItem tblPurchaseYearPeriodItem =
                                                SetToModelObject(objPrqPurchaseYearPeriodItem);
                                            _context.Prq_PurchaseYearPeriodItem.Add(tblPurchaseYearPeriodItem);
                                        }
                                        else
                                        {
                                            Prq_PurchaseYearPeriodItem CurrEntity =
                                                SetToModelObject(objPrqPurchaseYearPeriodItem);
                                            var OrgrEntity =
                                                _context.Prq_PurchaseYearPeriodItem.First(
                                                    m => m.PeriodItemID == objPrqPurchaseYearPeriodItem.PeriodItemID);

                                            OrgrEntity.ItemTypeID     = CurrEntity.ItemTypeID;
                                            OrgrEntity.LeatherType    = CurrEntity.LeatherType;
                                            OrgrEntity.LeatherStatus  = CurrEntity.LeatherStatus;
                                            OrgrEntity.SizeID         = CurrEntity.SizeID;
                                            OrgrEntity.TargetQuantity = CurrEntity.TargetQuantity;
                                            OrgrEntity.UnitID         = CurrEntity.UnitID;
                                            OrgrEntity.TargetValue    = CurrEntity.TargetValue;
                                            OrgrEntity.CurrencyID     = CurrEntity.CurrencyID;
                                            OrgrEntity.RecordStatus   = CurrEntity.RecordStatus;
                                        }
                                    }
                                }

                                #endregion
                            }
                            _context.SaveChanges();

                            #endregion

                            tx.Complete();
                            _vmMsg.Type = Enums.MessageType.Update;
                            _vmMsg.Msg  = "Updated Successfully.";
                        }
                    }

                    #endregion
                }
                else
                {
                    _vmMsg.Type = Enums.MessageType.Error;
                    _vmMsg.Msg  = "Period is not Properly Define.";
                }
            }
            catch
            {
                _vmMsg.Type = Enums.MessageType.Error;
                _vmMsg.Msg  = "Failed to Update.";
            }
            return(_vmMsg);
        }