Ejemplo n.º 1
0
        public async Task <ActionResult <InfProductTypeRegRespObj> > AddUpdateProductType([FromBody] AddUpdateInfProductTypeObj entity)
        {
            try
            {
                var user = await _serverRequest.UserDataAsync();

                InfProductTypeObj item = null;
                if (entity.ProductTypeId > 0)
                {
                    item = _repo.GetProductType(entity.ProductTypeId);
                    if (item == null)
                    {
                        return new InfProductTypeRegRespObj
                               {
                                   Status = new APIResponseStatus {
                                       IsSuccessful = false, Message = new APIResponseMessage {
                                           FriendlyMessage = "Item does not Exist"
                                       }
                                   }
                               }
                    }
                    ;
                }

                var domainObj = new inf_producttype();
                domainObj.ProductTypeId = entity.ProductTypeId > 0 ? entity.ProductTypeId : 0;
                domainObj.Name          = entity.Name;
                domainObj.Description   = entity.Description;
                domainObj.Active        = true;
                domainObj.Createdby     = user.UserName;
                domainObj.Createdon     = DateTime.Today;
                domainObj.Deleted       = false;
                domainObj.Updatedby     = user.UserName;
                domainObj.Updatedon     = entity.ProductTypeId > 0 ? DateTime.Today : DateTime.Today;

                var isDone = _repo.AddUpdateProductType(domainObj);
                return(new InfProductTypeRegRespObj
                {
                    ProductTypeId = domainObj.ProductTypeId,
                    Status = new APIResponseStatus {
                        IsSuccessful = isDone ? true : false, Message = new APIResponseMessage {
                            FriendlyMessage = isDone ? "successful" : "Unsuccessful"
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                var errorCode = ErrorID.Generate(5);
                _logger.Error($"ErrorID : {errorCode} Ex : {ex?.Message ?? ex?.InnerException?.Message} ErrorStack : {ex?.StackTrace}");
                return(new InfProductTypeRegRespObj
                {
                    Status = new APIResponseStatus {
                        IsSuccessful = false, Message = new APIResponseMessage {
                            FriendlyMessage = "Error Occurred", TechnicalMessage = ex?.Message, MessageId = errorCode
                        }
                    }
                });
            }
        }
Ejemplo n.º 2
0
        public bool AddUpdateProductType(inf_producttype model)
        {
            try
            {
                if (model.ProductTypeId > 0)
                {
                    var itemToUpdate = _dataContext.inf_producttype.Find(model.ProductTypeId);

                    //_dataContext.inf_producttype.Add(itemToUpdate);
                    _dataContext.Entry(itemToUpdate).CurrentValues.SetValues(model);
                }
                else
                {
                    _dataContext.inf_producttype.Add(model);
                }
                return(_dataContext.SaveChanges() > 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 3
0
        public InfProductTypeRegRespObj UploadProductType(List <byte[]> record, string createdBy)
        {
            try
            {
                List <inf_producttype> uploadedRecord = new List <inf_producttype>();
                if (record == null)
                {
                    return new InfProductTypeRegRespObj
                           {
                               Status = new APIResponseStatus {
                                   IsSuccessful = false, Message = new APIResponseMessage {
                                       FriendlyMessage = "Unsuccessful"
                                   }
                               }
                           }
                }
                ;
                ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
                if (record.Count() > 0)
                {
                    foreach (var byteItem in record)
                    {
                        using (MemoryStream stream = new MemoryStream(byteItem))
                            using (ExcelPackage excelPackage = new ExcelPackage(stream))
                            {
                                ExcelWorksheet workSheet = excelPackage.Workbook.Worksheets[0];
                                int            totalRows = workSheet.Dimension.Rows;

                                for (int i = 2; i <= totalRows; i++)
                                {
                                    var item = new inf_producttype
                                    {
                                        Name        = workSheet.Cells[i, 1].Value.ToString(),
                                        Description = workSheet.Cells[i, 2].Value.ToString()
                                    };
                                    uploadedRecord.Add(item);
                                }
                            }
                    }
                }
                if (uploadedRecord.Count > 0)
                {
                    foreach (var item in uploadedRecord)
                    {
                        var producttypeexist = _dataContext.inf_producttype.FirstOrDefault(x => x.Name.ToLower().Trim() == item.Name.ToLower().Trim());
                        if (producttypeexist != null)
                        {
                            producttypeexist.Name        = item.Name;
                            producttypeexist.Description = item.Description;
                            producttypeexist.Active      = true;
                            producttypeexist.Deleted     = false;
                            producttypeexist.Updatedby   = item.Updatedby;
                            producttypeexist.Updatedon   = DateTime.Now;
                        }
                        else
                        {
                            var accountType = new inf_producttype
                            {
                                Name        = item.Name,
                                Description = item.Description,
                                Active      = true,
                                Deleted     = false,
                                Createdby   = createdBy,
                                Createdon   = DateTime.Now,
                            };
                            _dataContext.inf_producttype.Add(accountType);
                        }
                    }
                }

                var response = _dataContext.SaveChanges() > 0;
                return(new InfProductTypeRegRespObj
                {
                    Status = new APIResponseStatus {
                        IsSuccessful = response ? true : false, Message = new APIResponseMessage {
                            FriendlyMessage = response ? "Successful" : "Unsuccessful"
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }