예제 #1
0
        public bool Save(MonthClosingDto item)
        {
            var result = false;

            if (item == null)
            {
                throw new Exception("Invalid Data Entry");
            }

            try
            {
                MONTH_CLOSING model;

                if (item.MonthClosingId > 0)
                {
                    //update
                    model = _repository.Get(c => c.MONTH_CLOSING_ID == item.MonthClosingId).FirstOrDefault();

                    if (model == null)
                    {
                        throw new BLLException(ExceptionCodes.BLLExceptions.DataNotFound);
                    }

                    Mapper.Map <MonthClosingDto, MONTH_CLOSING>(item, model);
                }
                else
                {
                    var activePlant = _plantBll.GetActivePlant();
                    var monthFlag   = item.ClosingDate.ToString("MMyyyy");

                    foreach (var plant in activePlant)
                    {
                        var newData = new MonthClosingDto();
                        newData         = item;
                        newData.PlantId = plant.WERKS;

                        var newModel = new MONTH_CLOSING();
                        newModel            = Mapper.Map <MONTH_CLOSING>(newData);
                        newModel.MONTH_FLAG = monthFlag;
                        newModel.IS_ACTIVE  = true;
                        _repository.InsertOrUpdate(newModel);
                    }
                }

                _uow.SaveChanges();

                result = true;
            }
            catch (Exception exception)
            {
                throw exception;
            }

            return(result);
        }
        public ActionResult Create(MonthClosingIndexViewModel model)
        {
            try
            {
                MonthClosingDto data = new MonthClosingDto();

                model.Details.MonthClosingDoc = new List <MonthClosingDocModel>();
                if (model.Details.MonthClosingFiles != null)
                {
                    int counter = 0;
                    foreach (var item in model.Details.MonthClosingFiles)
                    {
                        if (item != null)
                        {
                            var filenamecheck = item.FileName;

                            if (filenamecheck.Contains("\\"))
                            {
                                filenamecheck = filenamecheck.Split('\\')[filenamecheck.Split('\\').Length - 1];
                            }

                            var attachment = new MonthClosingDocModel()
                            {
                                FILE_NAME  = filenamecheck,
                                FILE_PATH  = SaveUploadedFile(item, model.Details.ClosingDate.ToString("MMyyyy"), counter),
                                MONTH_FLAG = model.Details.ClosingDate.ToString("MMyyyy")
                            };
                            model.Details.MonthClosingDoc.Add(attachment);
                            counter += 1;
                        }
                    }
                }

                data = Mapper.Map <MonthClosingDto>(model.Details);
                var monthClosingData = _monthClosingBll.Save(data);

                var docData             = Mapper.Map <List <MonthClosingDocDto> >(model.Details.MonthClosingDoc);
                var monthClosingDocData = _monthClosingDocBll.Save(docData);

                AddMessageInfo("Create Success", Enums.MessageInfoType.Success);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                AddMessageInfo(ex.Message, Enums.MessageInfoType.Error);
                model = InitialModel(model);
                return(View(model));
            }
        }