示例#1
0
        public async Task <IActionResult> Create([FromForm] MasterAssetBrand asset_Brand_Master)
        {
            if (ModelState.IsValid)
            {
                bool isCodeExist = _context.MasterAssetBrand.Any(m => m.Code.Equals(asset_Brand_Master.Code));
                if (isCodeExist)
                {
                    ModelState.AddModelError("Code", "Code Already Exists!");
                    return(View(asset_Brand_Master));
                    //return RedirectToAction(nameof(Create), new { error = "Code exists" });
                }

                string newJson      = JsonConvert.SerializeObject(asset_Brand_Master);
                bool   isCodeExists = IsCodeExists(asset_Brand_Master.Code);
                asset_Brand_Master.CompanyId       = 123;
                asset_Brand_Master.IsUsed          = true;
                asset_Brand_Master.Status          = asset_Brand_Master.Status;
                asset_Brand_Master.CreatedBy       = _configuration.GetValue <string>("HardcodeValue:Createdby");
                asset_Brand_Master.CreatedDatetime = DateTime.UtcNow;
                _context.Add(asset_Brand_Master);
                await _context.SaveChangesAsync();

                AuditService.InsertActionLog(asset_Brand_Master.CompanyId, asset_Brand_Master.CreatedBy, "Create", "Master Asset Brand", null, newJson);
                return(RedirectToAction(nameof(Index)));
            }
            return(View(asset_Brand_Master));
        }
示例#2
0
        public async Task <IActionResult> Edit(int id, [FromForm] MasterAssetBrand asset_Brand_Master)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    bool isCodeExist = _context.MasterAssetBrand.Any(m => m.Code.Equals(asset_Brand_Master.Code) && !m.Id.Equals(id));
                    if (isCodeExist)
                    {
                        ModelState.AddModelError("Code", "Code Already Exists!");
                        return(View(asset_Brand_Master));
                        //return RedirectToAction(nameof(Index), new { error = "Code exists" });
                    }

                    MasterAssetBrand db_asset_Brand_Master = _context.MasterAssetBrand.FirstOrDefault(m => m.Id.Equals(asset_Brand_Master.Id));
                    if (asset_Brand_Master == null || id != asset_Brand_Master.Id)
                    {
                        return(NotFound());
                    }

                    OldData oldData = new OldData();
                    oldData.Code   = db_asset_Brand_Master.Code;
                    oldData.Name   = db_asset_Brand_Master.Name;
                    oldData.Remark = db_asset_Brand_Master.Remark;
                    oldData.Status = db_asset_Brand_Master.Status;

                    string oldJson = JsonConvert.SerializeObject(oldData);
                    string newJson = JsonConvert.SerializeObject(asset_Brand_Master);

                    db_asset_Brand_Master.Code             = asset_Brand_Master.Code;
                    db_asset_Brand_Master.Name             = asset_Brand_Master.Name;
                    db_asset_Brand_Master.Status           = asset_Brand_Master.Status;
                    db_asset_Brand_Master.Remark           = asset_Brand_Master.Remark;
                    db_asset_Brand_Master.ModifiedBy       = _configuration.GetValue <string>("HardcodeValue:Createdby");
                    db_asset_Brand_Master.ModifiedDatetime = DateTime.UtcNow;
                    AuditService.InsertActionLog(db_asset_Brand_Master.CompanyId, db_asset_Brand_Master.CreatedBy, "Edit", "Master Asset Brand", oldJson, newJson);


                    _context.Update(db_asset_Brand_Master);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!Asset_Brand_MasterExists(asset_Brand_Master.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(asset_Brand_Master));
        }
示例#3
0
        private bool UpdateDm(string code, string name, string remark, bool status)
        {
            bool res = false;

            try
            {
                MasterAssetBrand asset_Brand_Master = _context.MasterAssetBrand.FirstOrDefault(m => m.Code.Equals(code));

                OldData oldData = new OldData();
                oldData.Code   = asset_Brand_Master.Code;
                oldData.Name   = asset_Brand_Master.Name;
                oldData.Remark = asset_Brand_Master.Remark;
                oldData.Status = asset_Brand_Master.Status;

                string oldJson = JsonConvert.SerializeObject(oldData);
                string newJson = JsonConvert.SerializeObject(asset_Brand_Master);

                if (asset_Brand_Master != null)
                {
                    asset_Brand_Master.Name             = name;
                    asset_Brand_Master.Code             = code;
                    asset_Brand_Master.Status           = status;
                    asset_Brand_Master.Remark           = remark;
                    asset_Brand_Master.ModifiedDatetime = DateTime.UtcNow;
                    asset_Brand_Master.ModifiedBy       = _configuration.GetValue <string>("HardcodeValue:Modifiedby");
                    AuditService.InsertActionLog(asset_Brand_Master.CompanyId, asset_Brand_Master.CreatedBy, "Edit", "Master Asset Brand", oldJson, newJson);
                    _context.SaveChanges();
                    res = true;
                }
            }
            catch (Exception ex)
            {
                res = false;
            }

            return(res);
        }
示例#4
0
        private bool CreateDm(string code, string name, string remark, bool status)
        {
            bool             res = false;
            MasterAssetBrand asset_Brand_Master = new MasterAssetBrand();

            try
            {
                NewData newData = new NewData();
                newData.Code   = code;
                newData.Name   = name;
                newData.Remark = remark;
                newData.Status = status;

                string newJson = JsonConvert.SerializeObject(newData);

                asset_Brand_Master.Code            = code;
                asset_Brand_Master.Name            = name;
                asset_Brand_Master.Remark          = remark;
                asset_Brand_Master.CompanyId       = 123;
                asset_Brand_Master.IsUsed          = true;
                asset_Brand_Master.Status          = status;
                asset_Brand_Master.CreatedBy       = _configuration.GetValue <string>("HardcodeValue:Createdby");
                asset_Brand_Master.CreatedDatetime = DateTime.UtcNow;
                _context.Add(asset_Brand_Master);
                AuditService.InsertActionLog(asset_Brand_Master.CompanyId, asset_Brand_Master.CreatedBy, "Create", "Master Asset Brand", null, newJson);

                _context.SaveChanges();
                res = true;
            }
            catch (Exception ex)
            {
                res = false;
            }

            return(res);
        }
示例#5
0
        public async Task <FileResult> Export()
        {
            string[] names = typeof(MasterAssetBrand).GetProperties().Select(property => property.Name).ToArray();

            string[] columnNames = new string[] { "Code", "Name", "Remark", "Status" };

            MasterAssetBrand entities = new MasterAssetBrand();

            var customers = await _context.MasterAssetBrand.ToListAsync();

            //Build the CSV file data as a Comma separated string.
            string csv      = string.Empty;
            bool   IsStatus = false;

            foreach (string columnName in columnNames)
            {
                //Add the Header row for CSV file.
                csv += columnName + ',';
            }

            //remove symbol "," behind
            csv = csv.Remove(csv.Length - 1, 1);

            //Add new line.
            csv += "\r\n";

            foreach (var customer in customers)
            {
                //Add the Data rows.
                csv += customer.Code.Replace(",", ";") + ',';
                csv += customer.Name.Replace(",", ";") + ',';
                if (customer.Remark != null)
                {
                    csv += customer.Remark.Replace(",", ";") + ',';
                }
                else
                {
                    customer.Remark = "";
                    csv            += customer.Remark.Replace(",", ";") + ',';
                }

                if (customer.Status != false)
                {
                    string Status = "YES";
                    csv += Status.Replace(",", ";");
                }
                if (customer.Status != true)
                {
                    string Status = "NO";
                    csv += Status.Replace(",", ";");
                }

                //Add new line.
                csv += "\r\n";
            }

            var file = "AssetBrandMaster.csv";

            //var file = ViewData;
            //Download the CSV file.
            byte[] bytes = Encoding.ASCII.GetBytes(csv);
            return(File(bytes, "application/text", file));
        }