コード例 #1
0
        //-> Create
        public async Task <ItemGroupViewDTO> Create(ItemGroupNewDTO newDTO)
        {
            newDTO = StringHelper.TrimStringProperties(newDTO);
            var checkName = await db.tblItemGroups.FirstOrDefaultAsync(r => r.itmg_Deleted == null && r.name == newDTO.name); // check whether itemgroup name exist or not

            if (checkName != null)
            {
                throw new HttpException((int)HttpStatusCode.BadRequest, "This name already exsits");
            }

            using (var transaction = db.Database.BeginTransaction())
            {
                try
                {
                    tblItemGroup itemGroup = (tblItemGroup)Helper.Helper.MapDTOToDBClass <ItemGroupNewDTO, tblItemGroup>(newDTO, new tblItemGroup());
                    itemGroup.itmg_CreatedDate = DateTime.Now;
                    db.tblItemGroups.Add(itemGroup);
                    await db.SaveChangesAsync();

                    List <sm_doc> documents = await Helper.Helper.SaveUploadImage(db, itemGroup.name, Helper.Helper.document_ItemGroupTableID, itemGroup.id, newDTO.images);// tmp not useful , just reserve data for using in the furture

                    transaction.Commit();
                    return(await SelectByID(itemGroup.id));
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw new Exception(ex.Message);
                }
            }
        }
コード例 #2
0
        //-> create
        public async Task <ItemViewDTO> Create(ItemNewDTO newDTO)
        {
            newDTO = StringHelper.TrimStringProperties(newDTO);
            var checkItemGroup = await db.tblItemGroups.FirstOrDefaultAsync(x => x.itmg_Deleted == null && x.id == newDTO.itemGroup.id); // check whether itemgroup name exist or not

            if (checkItemGroup == null)
            {
                throw new HttpException((int)HttpStatusCode.BadRequest, "Item group not exist");
            }

            var checkItemCode = await db.tblItems.FirstOrDefaultAsync(r => r.item_Deleted == null && r.code == newDTO.code); // check whether itemgroup name exist or not

            if (checkItemCode != null)
            {
                throw new HttpException((int)HttpStatusCode.BadRequest, "This item code already exsits");
            }

            using (var transaction = db.Database.BeginTransaction())
            {
                try
                {
                    if (string.IsNullOrEmpty(newDTO.description))
                    {
                        newDTO.description = newDTO.name;
                    }
                    tblItem item = (tblItem)Helper.Helper.MapDTOToDBClass <ItemNewDTO, tblItem>(newDTO, new tblItem());
                    item.item_CreatedDate = DateTime.Now;
                    item.cost             = 0;
                    item.quantity         = 0;
                    item.lastCost         = 0;

                    db.tblItems.Add(item);
                    await db.SaveChangesAsync();

                    List <sm_doc> documents = await Helper.Helper.SaveUploadImage(db, item.name, Helper.Helper.document_ItemTableID, item.id, newDTO.images);// tmp not useful , just reserve data for using in the furture
                    await SaveItemToWarehouses(item);

                    transaction.Commit();

                    return(await SelectByID(item.id));
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw new Exception(ex.Message);
                }
            }
        }
コード例 #3
0
ファイル: Helper.cs プロジェクト: seavty/x-admin-api
        //-- Save upload document --//
        public static async Task <List <sm_doc> > SaveUploadImage(THEntities db, string documentName, int tableID, int recordID, List <string> base64)
        {
            List <sm_doc> documents = new List <sm_doc>();

            if (base64 != null)
            {
                foreach (var image in base64)
                {
                    using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(image)))
                    {
                        string pathForSavingToDB = "", imageNameForSavingToDB = "";
                        using (Bitmap bm = new Bitmap(ms))
                        {
                            string path             = "";
                            string uploadFolderName = "uploads";
                            path = HttpContext.Current.Server.MapPath(@"~\" + uploadFolderName);
                            if (!Directory.Exists(path))
                            {
                                Directory.CreateDirectory(path);
                            }

                            string currentYear = DateTime.Now.Year.ToString();
                            path += @"\" + currentYear;
                            if (!Directory.Exists(path))
                            {
                                Directory.CreateDirectory(path);
                            }

                            string currentMonth = DateTime.Now.Month > 9 ? DateTime.Now.Month.ToString() : "0" + DateTime.Now.Month;
                            path += @"\" + currentMonth;

                            if (!Directory.Exists(path))
                            {
                                Directory.CreateDirectory(path);
                            }

                            var createImageUniqueName = recordID + "_" + DateTime.Now.ToString("yyyy-MM-dd_HHmmssfff") + ".jpg";
                            bm.Save(path + @"\" + createImageUniqueName);

                            imageNameForSavingToDB = documentName + "_" + createImageUniqueName;
                            pathForSavingToDB      = uploadFolderName + "/" + currentYear + "/" + currentMonth + "/" + createImageUniqueName;
                        }
                        var document = new sm_doc();
                        document.name             = imageNameForSavingToDB;
                        document.tableID          = tableID;
                        document.docs_CreatedDate = DateTime.Now;
                        document.value            = recordID.ToString();
                        document.path             = pathForSavingToDB;
                        db.sm_doc.Add(document);
                        await db.SaveChangesAsync();

                        documents.Add(document);
                    }
                }
            }
            return(documents);
        }
コード例 #4
0
        //-> Create
        public async Task <CustomerViewDTO> Create(CustomerNewDTO newDTO)
        {
            newDTO = StringHelper.TrimStringProperties(newDTO);
            var checkName = await db.tblCustomers.FirstOrDefaultAsync(x => x.cust_Deleted == null && x.name == newDTO.name); // check whether itemgroup name exist or not

            if (checkName != null)
            {
                throw new HttpException((int)HttpStatusCode.BadRequest, "This customer name already exsits.");
            }

            tblCustomer customer = (tblCustomer)Helper.Helper.MapDTOToDBClass <CustomerNewDTO, tblCustomer>(newDTO, new tblCustomer());

            customer.cust_CreatedDate = DateTime.Now;
            db.tblCustomers.Add(customer);
            await db.SaveChangesAsync();

            db.Entry(customer).Reload();
            return(await SelectByID(customer.id));
        }
コード例 #5
0
        public static async Task <List <sm_doc> > SaveUploadImage(THEntities db, int tableID, int recordID, List <string> base64)
        {
            List <sm_doc> documents = new List <sm_doc>();

            if (base64 != null)
            {
                foreach (var image in base64)
                {
                    using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(image)))
                    {
                        string pathForSavingToDB = "", imageNameForSavingToDB = "";
                        using (Bitmap bm = new Bitmap(ms))
                        {
                            //string path = "";
                            string year  = DateTime.Now.Year.ToString();
                            string month = DateTime.Now.Month > 9 ? DateTime.Now.Month.ToString() : "0" + DateTime.Now.Month;

                            /*
                             * path = ConstantHelper.UPLOAD_FOLDER + @"\" + year + @"\" + month;
                             * path = HttpContext.Current.Server.MapPath(@"~\" + path);
                             * if (!Directory.Exists(path))
                             *  Directory.CreateDirectory(path);
                             * var createImageUniqueName = $"{tableID}_{recordID}_{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss-fff")}.jpg";
                             * bm.Save(path + @"\" + createImageUniqueName);
                             * bm.Save(@"C:\uploads\" + createImageUniqueName);
                             */
                            var createImageUniqueName = $"{tableID}_{recordID}_{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss-fff")}.jpg";
                            var uploadPath            = WebConfigurationManager.AppSettings["uploadPath"].ToString();
                            uploadPath += ConstantHelper.UPLOAD_FOLDER + @"\" + year + @"\" + month;
                            if (!Directory.Exists(uploadPath))
                            {
                                Directory.CreateDirectory(uploadPath);
                            }
                            bm.Save(uploadPath + @"\" + createImageUniqueName);

                            imageNameForSavingToDB = createImageUniqueName;
                            pathForSavingToDB      = $"{ConstantHelper.UPLOAD_FOLDER}/{year}/{month}/{createImageUniqueName}";
                        }
                        var document = new sm_doc();
                        document.name             = imageNameForSavingToDB;
                        document.tableID          = tableID;
                        document.docs_CreatedDate = DateTime.Now;
                        document.value            = recordID.ToString();
                        document.path             = pathForSavingToDB;
                        db.sm_doc.Add(document);
                        await db.SaveChangesAsync();

                        documents.Add(document);
                    }
                }
            }
            return(documents);
        }
コード例 #6
0
        //-> Delete
        public async Task <Boolean> Delete(int id)
        {
            var saleOrder = await db.tblSaleOrders.FirstOrDefaultAsync(r => r.sord_Deleted == null && r.id == id);

            if (saleOrder == null)
            {
                throw new HttpException((int)HttpStatusCode.NotFound, "NotFound");
            }
            saleOrder.sord_Deleted = "1";
            await db.SaveChangesAsync();

            return(true);
        }
コード例 #7
0
        //-> Delete
        public async Task <Boolean> Delete(int id)
        {
            var record = await db.sm_doc.FirstOrDefaultAsync(x => x.docs_Deleted == null && x.id == id);

            if (record == null)
            {
                throw new HttpException((int)HttpStatusCode.NotFound, "NotFound");
            }
            record.docs_Deleted = "1";
            await db.SaveChangesAsync();

            return(true);
        }
コード例 #8
0
ファイル: UserRepository.cs プロジェクト: seavty/x-admin-api
        //-> Login
        public async Task <UserProfileViewHasToken> Login(UserCrendential crendential)
        {
            string password = Helper.Helper.EncryptString(crendential.password);
            var    user     = await db.sys_user.FirstOrDefaultAsync(r => r.user_Deleted == null && r.userName == crendential.userName && r.password == password);

            if (user == null)
            {
                return(null);
            }

            Guid token = Guid.NewGuid();

            user.token = Helper.Helper.EncryptString(token.ToString());
            await db.SaveChangesAsync();

            UserProfileViewHasToken userProfileWithToken = new UserProfileViewHasToken();

            userProfileWithToken.userProfile = await GetUserProfile(user.id);

            userProfileWithToken.token = token.ToString();

            return(userProfileWithToken);
        }