public JsonResult UploadLogo(AMCs modal)
        {
            JsonResponse resp = new JsonResponse();

            try
            {
                if (modal != null && modal.LogoFile != null && modal.LogoFile.Length > 0)
                {
                    var filename = Path.Combine(RandomString() + modal.LogoFile.FileName);
                    var path     = Path.Combine(_HostingEnvironment.WebRootPath, "Uploaded_Image", filename);
                    using (var fileStream = new FileStream(path, FileMode.Create))
                    {
                        modal.LogoFile.CopyTo(fileStream);
                    }
                    string filePath = Path.Combine(_HostingEnvironment.WebRootPath, "Uploaded_Image", filename);
                    //modal.LogoFileData = ReadFile(filePath, modal.LogoFile.FileName);
                    resp.Data   = filename;
                    resp.Status = Constants.ResponseStatus.Success;
                }
                else if (modal.Logo != null && modal.Id != 0)
                {
                    return(Json(_interface.CheckImage(modal)));
                }
                else
                {
                    resp.Message = Constants.ControllerMessage.Upload_Needed;
                }
            }
            catch
            {
                resp.Message = Constants.ControllerMessage.Upload_Failed;
            }
            return(Json(resp));
        }
Beispiel #2
0
        //public JsonResponse UploadLogo(AMCs modal)
        //{
        //    try
        //    {
        //        if (modal != null)
        //        {
        //            var updateModal = _context.aMCs.Where(e => e.Id == modal.Id).FirstOrDefault();

        //            updateModal.Logo = modal.LogoFile.FileName;
        //            updateModal.ModifiedBy = 1;
        //            updateModal.ModifiedOn = DateTime.UtcNow;
        //            _context.aMCs.Update(updateModal);
        //            if (_context.SaveChanges() > 0)
        //            {
        //                resp.Status = Constants.ResponseStatus.Success;
        //                resp.Message = "Record Updated Successfully";
        //            }
        //            else
        //            {
        //                resp.Status = "F";
        //                resp.Message = "Image not upload. please try again!";
        //            }
        //        }
        //        else
        //        {
        //            resp.Status = "F";
        //            resp.Message = "something went wrong !";
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        StackTrace CallStack = new StackTrace(ex, true);
        //        ex.Data["ErrDescription"] = ex.Data["ErrDescription"] != null ? ex.Data["ErrDescription"] : string.Format("Error captured in {0} on Line No {1} of Method {2}", CallStack.GetFrame(0).GetFileName(), CallStack.GetFrame(0).GetFileLineNumber(), CallStack.GetFrame(0).GetMethod().ToString());
        //        throw ex;
        //    }
        //    return resp;
        //}

        /// <summary>
        /// Check Image in the database
        /// </summary>
        /// <param name="modal"></param>
        /// <returns>Jsonresponse</returns>
        public JsonResponse CheckImage(AMCs model)
        {
            //Check the Image file name in the model and return the values if the condition true it retun the model logo name.
            if (_context.AMC.Where(e => e.Logo == model.Logo).FirstOrDefault() != null)
            {
                resp.Status = Constants.ResponseStatus.Success;
                resp.Data   = model.Logo;
            }
            // Else the error function was trigger and send the message.
            else
            {
                resp.Message = Constants.Service.Common_message;
            }
            return(resp);
        }
Beispiel #3
0
 /// <summary>
 /// Add Update Data
 /// </summary>
 /// <param name="model"></param>
 /// <returns>Jsonresponse</returns>
 public JsonResponse AddUpdate(AMCs model)
 {
     try
     {
         //  If these condition true the data was not exsits in the database
         if (!IsExsits(model.Name, model.Id))
         {
             //  If model.ID == 0 the data goes to the Add part.
             if (model.Id == 0)
             {
                 model.IsActive  = true;
                 model.CreatedOn = DateTime.Now;
                 model.CreatedBy = GetUserID();
                 _context.Set <AMCs>().Add(model);
                 int i = _context.SaveChanges();
                 //  If i != 0 means it affect one data So the data was Inserted.
                 if (i != 0)
                 {
                     resp.Status  = Constants.ResponseStatus.Success;
                     resp.Message = Constants.Service.Data_insert_success;
                 }
                 //esle It gives some error in data insertion.
                 else
                 {
                     resp.Message = Constants.Service.Data_insert_failed;
                     var file = Path.Combine(_HostingEnvironment.WebRootPath, "NewFolder", model.Logo);
                     if (File.Exists(file))
                     {
                         File.Delete(file);
                     }
                 }
             }
             //  Else data goes to the Update part.
             else
             {
                 resp.Message = Constants.Service.Data_Update_failed;
                 var models = GetData(model.Id);
                 // If the models not null it get the database data belongs to the ID
                 if (models != null)
                 {
                     models.Name       = model.Name;
                     models.Address    = model.Address;
                     models.IsActive   = true;
                     models.ModifiedOn = DateTime.Now;
                     models.ModifiedBy = GetUserID();
                     _context.Set <AMCs>().Update(models);
                     int i = _context.SaveChanges();
                     if (i != 0)
                     {
                         resp.Status  = Constants.ResponseStatus.Success;
                         resp.Message = Constants.Service.Data_Update_success;
                     }
                 }
             }
         }
         // The data was in the database so, It return the else part
         else
         {
             resp.Message = Constants.ControllerMessage.Data_Exsists;
         }
     }
     catch (Exception)
     {
         resp.Message = Constants.Service.Common_message;
     }
     return(resp);
 }